-
Just a nitpicky question
Hey, I just thought of a really really nitpicky question. Does the ! operator (it is an operator, right?) make any difference in speed whatsoever? I mean, would there be any difference at all in the speed of these code examples?
Code:
//Clip 1
bool done = false;
while(!done)
//stuff
//Clip 2
bool notDone = true;
while(notDone)
//stuff
It doesn't really matter to me, and I know that most people would use the first code example, but just had a sudden curiosity attack.
-
Some speed... probably.
Noticeable... not really
However, your compiler might optimize something like that.
-
I'm going to say no.
In assembly that's just a difference of conditional jumps. JE vs. JNE (Jump if Equal, Jump if Not Equal)
This is what VC6 output:
Code:
while (!done)
0040117C mov eax,dword ptr [ebp-4]
0040117F and eax,0FFh
00401184 test eax,eax
00401186 jne main+48h
Code:
while (notdone)
0040117C mov eax,dword ptr [ebp-4]
0040117F and eax,0FFh
00401184 test eax,eax
00401186 je main+48h
As you can see, the only difference between the two is the different jumps. I doubt one is any faster than the other.
-
>I mean, would there be any difference at all in the speed of these code examples?
Before optimization, possibly, after optimization, I would be very surprised.
-Prelude
-
Ok, thanks :) my curiosity is satisfied.