++i is supposed to be faster than i++ right?? Then why this o/p ?? Below is the code in CPP
start = clock();
srand(time(NULL));
cout<<"++i"<<endl;
for(int i=0;i!=-1;++i);
end = clock();
total_time = ((double) (end - start)) / CLOCKS_PER_SEC;
cout<<"Time taken for ++i : "<<total_time<<"\n\n";
start = clock();
srand(time(NULL));
cout<<"i++"<<endl;
for(int i=0;i!=-1;i++);
end = clock();
total_time = ((double) (end - start)) / CLOCKS_PER_SEC;
cout<<"Time taken for i++ : "<<total_time<<endl;
And this is the output
++i Time taken for ++i : 12.2812
i++ Time taken for i++ : 12.125