For C++ programmers:
According to Microsoft the prefix iterator ++ is faster then the postfix version.
So ++i is faster then i++.
I've tested this. Let me present the code first.
Code:
// PerformanceCheck.cpp : Defines the entry point for the console application.
//
#include "stdafx.h" //Holds <iostream.h>, <time.h>
long double i = 0;
int main(int argc, char* argv[])
{
clock_t start, end;
long double duration;
start=clock();
for(i;i<4000000000;i++)
{i++;}
end=clock();
duration=(long double)(end-start)/CLOCKS_PER_SEC;
cout<<"Elapsed time: "<<duration<<endl;
return 0;
}
Check out "i". This loop (four billion!) executes "i++" (and ++i) only.
In the code, I take the time before the loop starts and after the loop ends.
Result on my 2GHz machine:
i++: between 11.093 seconds and 11.125 seconds.
++i: EXACTLY the same.
Test repeats: 1000.
*.exe mode: release, optimization for speed. One thread.
Congratulation Microsoft in fooling tons of programmers.
Why did I test this?
I am currently involved in a beta testers group for BattleZone2 1.3b. The lead programmer added a comment that he changed all instances of "i++" to "++i" because MS said it is slightly faster. Luckily the programmer said he doesn't trust MS but he managed to change all the instances without testing!!
ROFL. As soon as the BZ2 boards are up again ima gonna post this hehe