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
public:
    usecTimer() {
        QueryPerformanceFrequency(&_pc_freq);
        _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
elapsed()
    {
        return double((std::numeric_limits<LONGLONG>::max)()) /
double(_pc_freq.QuadPart);
    }

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

private:
    LARGE_INTEGER _pc_freq, _now_tic;
    double _start_time;
    double HFClock(void)
    {
        assert(_pc_freq.QuadPart != 0);
        // Query current clock tick
        QueryPerformanceCounter(&_now_tic);
        return double(_now_tic.QuadPart) / double(_pc_freq.QuadPart);
    }
#endif
};

>
> 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 acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk