Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2006-06-26 05:17:11


"Jeff Garland" wrote
> As for the interface, I'm almost amused that this pretty much trivial
> interface continues to bring discussion. The timer proposal that's in the
> vault now had the interface discussed at some length (see
> http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?GDTL/Timer) for
> some links. The sketch for this is:
>
> class timer {
> timer(time_duration initial_duration = time_duration(0,0,0),
> START_OPTION start_op = AUTO_START);
>
> void start();
> void restart() ;
> time_duration elapsed() const;
> void pause();
> void resume();
> void reset();
> };

FWIW I thought I should add my own timer efforts. None too serious, but the
unique (AFAICS) feature is that you can select different time units:
Its in <boost/pqs/utility/timer.hpp> and looks like this( This version moved to
quan namespace) :

amespace quan{

    template <typename TimeType = quan::time::ms>
    class timer{
    public:
        timer();
        void restart();
        void stop() ;
        TimeType operator ()()const;
        bool is_running() const ;
        bool is_stopped() const;
    };
}//quan
int main()
{
    int const num_loops=10;
    quan::timer<quan::time::ms> t; // construction starts timing
    for(int j = 0; j < num_loops; ++j){
       /*...*/
    }
    t.stop();
    std::cout << t() << "\n";
}

regards
Andy Little


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