I have the following two loops:
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main(){
int start=clock();
for (int i=0;i<100;i++)
cout<<i<<" "<<endl;
cout<<clock()-start<<"\n"<<endl;
cout<<"\n";
int start1=clock();
for (int j=0;j<100;++j)
cout<<j<<" "<<endl;
cout<<"\n";
cout<<clock()-start1<<" \n "<<endl;
return 0;
}
I ran that three times. On the first two runs, the second loop was fastest but, on the third run, the first loop was fastest. What does this mean? Which is better? Does it depend on the situation?