Boost logo

Boost :

From: Beman Dawes (beman_at_[hidden])
Date: 2000-09-14 13:42:48


At 01:30 PM 9/7/2000 +0000, William Kempf wrote:

>I considered this, but stuck with GetTickCount() because it is
>platform specific code and GetTickCount() returns milliseconds,
>whereas clock() would have to be used in a mathematical calculation
>using CLOCKS_PER_SEC to determine milliseconds. So GetTickCount()
>seemed safe and much easier to deal with for this specific case.

As a point of information, John Maddock sent me a version of the boost
timer functions implemented using Win32 native calls to
QueryPerformanceCounter rather than std::clock().

We ran some timings, and the results were quite surprising:

     * For a given compiler, clock() was sometimes dramatically (10 times)
faster that the native function. This is counter intuitive since the
native function had better resolution.
     * Which was faster varied from compiler to compiler. On John's
machine, the fastest clock() was over 70 times faster that the slowest.
     * Which was faster varied from platform to platform. The
characteristics of the timings on Win 95/98 were different from the Win NT
timings, even when adjusted for differing hardware.

The results were so varied that about the only thing you could say is that
to truly optimize timing, you might have to make the clock() vs
QueryPerformanceCounter() trade-off as late as run-time.

Just a cautionary tale...

--Beman


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk