The accepted answer should be updated:
fdisk -l /dev/sdb
Disk /dev/sdb: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 6C5ED23-xxxxxxx
As you can see, fdisk now shows Disklabel type: gpt without needing to parse error messages.
time fdisk: real 0m0.004s
time parted: real 0m0.413s
100x slower for parted.
I was researching this for another application that needed this data, so I'm just updating the slightly out of date fdisk information. Also because when one program is 100x faster than another, it's usually worth taking a closer look at it in general.
I don't know which version of fdisk brought in this change.
The above is: 2.30.2
I found one in an older systems that shows gpt error, versions 2.20.1, but I don't know which specific fdisk version corrected this issue.
Note that the gpt error is going to stderr, so if you were sending errors to 2>/dev/null you'd miss that message.