Your methodology is flawed. Your loop increment and condition checking itself is taking that much time.
Try running an empty loop and measure the time (call it base). Now add 1 shift operation and measure the time (call it s1). Next add 10 shift operations and measure the time (call it s2)
- Try running an empty loop and measure the time (call it
base). - Now add 1 shift operation and measure the time (call it
s1). - Next add 10 shift operations and measure the time (call it
s2)
If everything is going correctly base-s2 should be 10 times more than base-s1. Otherwise something else is coming into play here.
Now I actually tried this myself and figured, If loops are causing a problem why not remove them entirely. So I went ahead and did this :
int main(){ int test = 2; clock_t launch = clock(); test << 6; test << 6; test << 6; test << 6; //.... 1 million times test << 6; clock_t done = clock(); printf("Time taken : %d\n", done - launch); return 0; } And there you have your result
1 million shift operations in under 1 milisecondmiliseconds ?.
I did the same thing for multiplication by 64 and got the same result. So probably the compiler is ignoring the operation completely as others mentioned the value of test is never changed.
