This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: clock and timing.
- To: Michael Veksler <VEKSLER at il dot ibm dot com>, opentest at angelfire dot com
- Subject: Re: clock and timing.
- From: Der Herr Hofrat <der dot herr at hofr dot at>
- Date: Mon, 22 Oct 2001 14:21:41 +0200 (CEST)
- CC: gcc-help at gcc dot gnu dot org
>
> This has nothing to do with gcc. On many systems clock()'s resolution
> is only 1/100 of a second. This means that clock() is incremented
> every 10,000/CLOCKS_PER_SEC seconds.
>
>
>
> "Tom Davids" <opentest@angelfire.com>@gcc.gnu.org on 22-10-2001 06:14:31
>
> > I've just coded up this small program
>
> > [ deleted a program that uses clock() ]
> >
> > The CLOCKS_PER_SEC is 1000000,
> > When I run the program I get the either
> > total = 10000
> > total = 20000
> > or
> > total = 0.
>
you are seeing the "ticks" of the OS not of the hardware - if you need a high
resolution clock then you need to directly read the hardware clock - for X86
on a Linux system this could be done by
----snip---
#include <stdio.h>
#include <asm/io.h>
__inline__ unsigned long long int hwtime(void)
{
unsigned long long int x;
__asm__("rdtsc\n\t"
"mov %%edx, %%ecx\n\t"
:"=A" (x));
return x;
}
main(){
long long int hwtime1,hwtime2,jitt,jitt_max;
jitt_max=0;
while(1){
hwtime1 = hwtime();
hwtime2 = hwtime();
jitt=hwtime2-hwtime1;
if(jitt > jitt_max){
jitt_max=jitt;
printf("got %lx\n",jitt);
}
sleep(1);
}
return;
}
this would show you the "hardware-resolution" of the system if you let it run
for a while. On a normal linux system you will see worst-case jitter of up to
1 second (PIII/800 Running a 2.4.4 kernel).
hofrat