lkml.org 
[lkml]   [2003]   [Jan]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: timing an application
On Tue, 14 Jan 2003, Maciej Soltysiak wrote:

> Hi,
>
> being inspired by some book about optimizing c++ code i decided to do
> timing of functions i wrote. I am using gettimeofday to set
> two timeval structs and calculate the time between them.
> But the results depend heavily on the load, also i reckon that this
> is an innacurate timing.
>
> Any ideas on timing a function, or a block of code? Maybe some kernel
> timers or something.
>
> Regards,
> Maciej Soltysiak
>

Easy! Use the rdtsc instruction to obtain the number of CPU cycles
that occur between two subsequent calls. There will be some 'noise'
because of interrupt activity so make many tests, put the results
into an array, remove the slowest and the fastest, then average
the remaining data. That's good enough for "government projects".

Cheers,
Dick Johnson
Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.

[unhandled content-type:application/octet-stream]
\
 
 \ /
  Last update: 2005-03-22 13:32    [W:0.059 / U:4.680 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site