
Komag
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2015
08:24 AM
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.
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.
1 REPLY 1
EnTerr
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2015
11:20 AM
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,
The difference is a part of a microsecond and will become significant when you start doing that thousands of 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.