Mail Archives: djgpp/1998/03/08/13:31:14
Hi!
Recently I tried to measure the time some functions executes itself and
I used clock() function to do that.
I was surprized because sometimes clock() returned different values even
though my function performed exactly the same job.
I have written a short test:
#include <stdio.h>
#include <time.h>
#include <math.h>
int main()
{
clock_t start_time, end_time;
long i;
start_time=clock();
for (i = 0; i < 1000000; i++)
{
double root=sqrt(2.0);
}
end_time=clock();
printf("total time=%f\n",
(double)(end_time-start_time)/CLOCKS_PER_SEC);
}
and while executing it I get mostly:
"total time=0.549310"
but sometimes I get:
"total time=0.494379"
and sometimes I get:
"total time=0.604241"
Can anyone explain why something like that happens.
Is it possible to cause that I get the same result every time I call
clock() function seqence.
- Raw text -