this is a simple test of performance for checking if a uint8
(commonly used for bit flags) is non-zero.
u > 0
is the slowest, averaging 1.14ns/op.u != 0
is a little faster, averaging 1.13ns/op.- casting
u
tobool
is the fastest, averaging 0.98ns/op.
note: the third method is unsafe, and only confirmed to work on linux
/amd64
, where a non-zero byte is truthy.