nested if statements
Hi a simple question:
Does using three nested 'if' staments incur less overhead than having all three conditions in one? Several simple tests I ran seem to suggest the former. But maybe thats just an unfounded observation ;o)
cheers
Well, if they were all combined, that's less file size... (If I'm understanding you post here..)
Assuming C++ (and other languages with short circuit evaluation) and assuming that you are using non overloaded versions of || or && to combine conditions, then there should be no difference in the nested if statements and the three conditions in one. Of course, you might be doing something extra funky (like overloading &&) that could make that statement false.
Nothing funky. It was just one of those things I was curious about as I was writing them up... "is there really a difference". The tests were simply a counter inside one the two possibilities. Keep track of how long it takes to reach a certain number. Run each many many times. And see if there is a pattern. Shorter times tended most of the time to lean towards broken up conditions. Im using VC++6 and maybe another one of those oddities on the list of things it does that arent the norm.
Or maybe not ;o)
Cheers
Or maybe not ;o)
Cheers
Probably not. I recall short-circuiting working just fine in VC6. The nature of short-circuit evaluation, in fact, is such that it's actually somewhat easier to implement it than to not implement it; you can just stick a conditional jump after each test, instead of accumulating the boolean result somewhere.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement