Silly precision in a timing macros
Andreas Ericsson
ae at op5.se
Fri Oct 29 01:55:01 CEST 2004
Jason Martin wrote:
> On Thu, Oct 28, 2004 at 05:47:50PM -0500, Ethan Galstad wrote:
>
>>>The precision provided by timing macros (for latency and executin
>>>times) are a bit silly, since it holds room for 6 decimal points but
>>>only ever uses 3 of them (a limit in the Linux kernel, I've heard).
>
> I'm surprised about that; some of my perl scripts can print time
> periods to 6 decimal points.
>
You really shouldn't trust computer generated timings beyond the fourth
decimal point. They are rough estimates at the very best.
Taken from the nanosleep(2) manpage;
BUGS
The current implementation of nanosleep is based on the normal kernel
timer mechanism, which has a resolution of 1/HZ s (i.e, 10 ms on
Linux/i386 and 1 ms on Linux/Alpha).
> The perl module is Time::HiRes.
> If I do something like this:
>
> #Track execution time
> my $t0 = [gettimeofday];
> //[misc stuff]
> print "Stored data for $var on $var2 in " . tv_interval($t0);
>
> , I can get output such as:
> Stored data for ****** on ****** in 0.004562s
>
> Perhaps there is some other limitation causing the time
> precision to be lowered?
>
The nanosleep(2) manpage talks about microprecision values being
possible to obtain using busy waits. Busy waits for timing reasons would
be very impractical to implement in the kernel (except for waits that
really are busy), but I suppose an application could use them if that
same application was willing to trade a large portion of efficiency for
timing purposes (multithreaded apps using on-the-fly created threads
might have to do this, but I've never seen one that doesn't other
workarounds instead. 'Manual' thread synchronization is usually
considered too difficult to implement and generally come as a result of
poor design to begin with).
--
Andreas Ericsson andreas.ericsson at op5.se
OP5 AB www.op5.se
Lead Developer
-------------------------------------------------------
This Newsletter Sponsored by: Macrovision
For reliable Linux application installations, use the industry's leading
setup authoring tool, InstallShield X. Learn more and evaluate
today. http://clk.atdmt.com/MSI/go/ins0030000001msi/direct/01/
More information about the Developers
mailing list