Code:
#include <stdio.h>
#include <time.h>
int main()
{
double start, finish, elapsed;
int temp1, temp2;
start = (double) clock()/CLOCKS_PER_SEC;
temp2 = 0;
for(temp1 = 0; temp1<1000000000; temp1++)
{
temp2 = temp2+1;
}
finish = (double) clock()/CLOCKS_PER_SEC;
elapsed = finish-start;
printf("The elapsed time is %lf seconds\n", elapsed);
return;
}
Code:
#include <stdio.h>
#include <time.h>
int main()
{
double start, finish, elapsed;
int temp1, temp2;
start = (double) clock()/CLOCKS_PER_SEC;
temp1 = 0, temp2 = 0;
while(temp1 < 1000000000)
{
temp2 = temp2+1;
temp1++;
}
finish = (double) clock()/CLOCKS_PER_SEC;
elapsed = finish-start;
printf("The elapsed time is %lf seconds\n", elapsed);
return;
}
Anybody else want to run this code & see what results they get?
I have gotten that the while loop is actually 1/100 th of a second faster (.01).