Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Roku Guru

Which is faster, checking a bool is True, or an integer > 0?

Just planning ahead a bit with code decisions. I usually do what makes the most sense for readability, etc. But sometimes it really doesn't matter as far as that goes, but might matter for speed for something I need to do every frame, so I search for the fastest method.

Is there any difference between checking whether a boolean is true vs checking an integer is > 0 (or whatever)? I can't tell any difference at this point, but I just wonder if down the road it will add enough to matter.
0 Kudos
Roku Guru

Re: Which is faster, checking a bool is True, or an integer

This is a YAGNI concern, it won't make any difference if you are doing that check once (or a few hundred times) per frame.

But since you asked,
IF myBoolVar THEN ...
' is a bit faster than
IF myIntVar > 0 THEN ...
' or
IF myBoolVar = true THEN ... ' why check "=true"?! good for readability, not so much for speed

The difference is a part of a microsecond and will become significant when you start doing that thousands of times per frame.
0 Kudos