public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: clock and timing.
@ 2001-10-22  5:28 Michael Veksler
  2001-10-22  5:36 ` Der Herr Hofrat
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Veksler @ 2001-10-22  5:28 UTC (permalink / raw)
  To: opentest; +Cc: gcc-help

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.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: clock and timing.
  2001-10-22  5:28 clock and timing Michael Veksler
@ 2001-10-22  5:36 ` Der Herr Hofrat
  0 siblings, 0 replies; 3+ messages in thread
From: Der Herr Hofrat @ 2001-10-22  5:36 UTC (permalink / raw)
  To: Michael Veksler, opentest; +Cc: gcc-help

> 
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* clock and timing.
@ 2001-10-21 21:14 Tom Davids
  0 siblings, 0 replies; 3+ messages in thread
From: Tom Davids @ 2001-10-21 21:14 UTC (permalink / raw)
  To: gcc-help

I've just coded up this small program

#include <stdio.h>
#include <time.h>

main(){
clock_t start, stop, total;
int count;

start = clock();
printf("%d\n", CLOCKS_PER_SEC);
for(count=0; count < 200000; count++);
stop = clock();
total=stop-start;
printf("total = %lu\n", total);

}                    

The CLOCKS_PER_SEC is 1000000,
When I run the program I get the either
total = 10000
total = 20000
or
total = 0.

Could someone explain what the numbers range so much when the CLOCKS_PER_SEC is so high.
Any help is highly apprieciated.
Thanks


Get 250 color business cards for FREE!
http://businesscards.lycos.com/vp/fastpath/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-10-22  5:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-22  5:28 clock and timing Michael Veksler
2001-10-22  5:36 ` Der Herr Hofrat
  -- strict thread matches above, loose matches on Subject: below --
2001-10-21 21:14 Tom Davids

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).