4.17. TimerCountdown CLASS

TimerCountdown class helps to keep track of the time spent in a function. This class subtracts the time elapsed between instantiation and destruction time from the timeval argument passed to its constructor.


class TimerCountdown

    TimerCountdown (TimeVal* wait_time_);
    ~TimerCountdown ();

4.17.2. USAGE

For example, if we want to know how much time is spent in a function call, then following can be employed:

void sluggard (TimeVal* tv_)
    TimerCountdown traceTime (tv_);

    // do time-intensive calculation ...

void foo ()
    TimeVal time_spent (60, 0);   // 60 seconds

    sluggard (&time_spent);

    cout << "Time remaining: " << TimeVal.fmtString();