Re: Reliable timing using RDTSC
- From: Mark Jones <spamtrap@xxxxxxxxxx>
- Date: Sun, 31 Dec 2006 18:03:25 -0500
Brendan wrote:
Hi,
Magnum Innominandum wrote:
Argh! Help! Is there any way to produce reliable, repeatable timings of
my code?
You can disable interrupts and context switches, and (depending on your
chipset and evironment) disable NMIs and SMIs. After that you'd want to
ensure that no power management (e.g. thermal throttling, STPCLK,
SpeedStep, etc) is going to influence the results. Then you can
serialise, but you'll still get different results due to different
amounts of things in CPU caches before you start. Flushing the caches
can be done by WBINVD and modifying CR0 (or CR3 if global pages aren't
a concern).
Of course after you've done all this the measurements you make should
be much more reliable, but they might also be useless in that the
results will indicate how long the code takes in very
specific/artificial circumstances and not how long it takes in
practice.
The same can be said for the normal technique of measuring the code N
times, discarding the first result (ignore the first run which will be
different due to cache loads), ignoring any higher than normal results
(IRQs and context switches) and working out the average. This tends to
work out the "almost best case" time, which will be significantly
different to the time the code would take in practice (when the code is
more likely to be run with a partially cold caches).
Then there's different CPUs. If you knew exactly how fast a piece of
code is on one CPU, then it won't tell you much about how fast the code
is on other CPUs.
Also, consider setting the test code thread to HIGH_PRIORITY_CLASS or
REALTIME_PRIORITY_CLASS. This will mitigate part of the pre-emptive multitasking
overhead (at the expense of system stability.)
MichaelW and Petroizki have made some great Win32 timing libs for MASM32. Check
it out: http://www.masm32.com/board/index.php?topic=3724.0
.
- References:
- Re: Reliable timing using RDTSC
- From: Brendan
- Re: Reliable timing using RDTSC
- Prev by Date: Re: Reliable timing using RDTSC
- Next by Date: Get the FAQs
- Previous by thread: Re: Reliable timing using RDTSC
- Next by thread: Re: Reliable timing using RDTSC
- Index(es):
Relevant Pages
|
Loading