Boost logo

Boost :

From: Alkis Evlogimenos (alkis_at_[hidden])
Date: 2003-05-21 02:44:09


On Tuesday 20 May 2003 11:31 pm, Jeff Garland wrote:
> The attached files contain the timer class including the implementation, a
> preliminary test program that has traits types for both the wallclock timer
> and the clock_t timer. Note the wallclock timer is not currently portable
> to non-posix systems. Test output from Linux with gcc 3.2. Feedback
> appreciated.

One thing that is missing from both the proposed timers and Boost Timer is an
elapsedAndRestart() method. Consider an application of a timer which is
measuring (using wallclock timers) the time to acquire and the time holding a
mutex. Using todays interface:

timer t;
mtx.lock();
double timeToAcquire = t.elapsed();
t.restart();
// do stuff
mtx.unlock();
double timeHeld = t.elapsed();

the above needs 4 calls to gettimeofday()/clock_gettime() (1 in constructor, 1
in restart and 1 in each of the elapsed calls). Using an elapsedAndRestart()
method this can go down to 3 calls:

timer t;
mtx.lock();
double timeToAcquire = t.elapsedAndRestart();
// do stuff
mtx.unlock();
double timeHeld = t.elapsed();

Maybe this is not such a good example because you can use timeToAcquire to
compute timeHeld without calling timer::restart() effectively reduceingthe
calls to 3, but in some cases you do not have the value of timeToAcquire at
that point (for example measurements are taken inside a scoped lock and
inserted in a histogram as they are gathered).

-- 
Alkis

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