From: Der Herr Hofrat <der.herr@hofr.at>
To: Michael Veksler <VEKSLER@il.ibm.com>, opentest@angelfire.com
Cc: gcc-help@gcc.gnu.org
Subject: Re: clock and timing.
Date: Mon, 22 Oct 2001 05:36:00 -0000 [thread overview]
Message-ID: <200110221221.f9MCLf728522@hofr.at> (raw)
In-Reply-To: <OF07221388.66420E3D-ONC2256AED.0043F6DF@telaviv.ibm.com>
>
> 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
next prev parent reply other threads:[~2001-10-22 5:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-10-22 5:28 Michael Veksler
2001-10-22 5:36 ` Der Herr Hofrat [this message]
-- strict thread matches above, loose matches on Subject: below --
2001-10-21 21:14 Tom Davids
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200110221221.f9MCLf728522@hofr.at \
--to=der.herr@hofr.at \
--cc=VEKSLER@il.ibm.com \
--cc=gcc-help@gcc.gnu.org \
--cc=opentest@angelfire.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).