Boost logo

Boost :

From: Brannon King (brannonking_at_[hidden])
Date: 2006-05-21 12:47:26

If anybody cares, here's the QPC counter overload I've been using. It
has the same functionality as the timer class. I could do a similar one
using gettimeofday on Linux if somebody is interested.

class usecTimer : public timer{
#ifdef WIN32
    usecTimer() {
        _start_time = HFClock();
    } // postcondition: elapsed()==0
    void restart() { _start_time = HFClock(); } // post: elapsed()==0
    double elapsed() // return elapsed time in seconds
    { return HFClock() - _start_time;

    double elapsed_max() const // return estimated maximum value for
        return double((std::numeric_limits<LONGLONG>::max)()) /

    double elapsed_min() const // return minimum value for
    { return (1.0 / double(_pc_freq.QuadPart)); }

    LARGE_INTEGER _pc_freq, _now_tic;
    double _start_time;
    double HFClock(void)
        assert(_pc_freq.QuadPart != 0);
        // Query current clock tick
        return double(_now_tic.QuadPart) / double(_pc_freq.QuadPart);

> Because of the long discussion about QueryPerformanceCounter that
> didn't came to a real conclusion, I decided to implement two
> additionnal timers:
> - boost::qpc_timer, which use QueryPerformanceCounter() for its
> resolution.
> - boost::tgt_timer, which use timeGetTime() for its resolution.
> As using those timers would make no sense on another platform than
> windows, those are not defined by default. One must #define
> BOOST_QPC_TIMER to get boost::qpc_timer and must #define
> BOOST_TGT_TIMER to get boost::tgt_timer.
> Trying to do those defines on another platform than windows results in
> an #error.

Boost list run by bdawes at, gregod at, cpdaniel at, john at