Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2003-05-21 07:39:48

> > Also, it has a total_elapsed duration
> > value which means that rollover issues are reduced for clock_t
> > type implementations since the total_elapsed is snapped when
> > the timer is stopped.
> But total_elapsed is only updated when the timer is stop'ed thus
> you need to stop so you need to stop and start once before
> every wraparound of clock().

As I mentioned the proposal doesn't solve all the problems with
various implementations of clock measurement.

> Next the total_duration_type can not
> be clock_t which would seem the logical choice.

No, clock_t is not a good choice here. This is intended to be a something
like a time_duration from the date_time library.

> I think the specialisation
> for using clock() will not be straightforward. BTW the implementation
> of clear_elapsed will never work for clock_t, I suggest using the
> default-constructor instead for zero-ing the total_elapsed
> (but I would not store total_elapsed as I'll explain below).

Did you look at the attached test program which had this traits adapter?

   //Measure amount of processor time used by process
  class clockt_timer_traits
    typedef std::clock_t time_rep;
    typedef boost::posix_time::time_duration time_duration_type;
    static time_rep init_zero()
      return 0;
    static time_rep get_current_time()
      return std::clock();
    //turns out posix_time and CLOCKS_PER_SEC are normally equal
    //at 1000000 so fractional seconds is simply end - start
    //check with
    // std::cout << CLOCKS_PER_SEC << std::endl;
    // std::cout << time_duration::rep_type::res_adjust() << std::endl;
    static time_duration_type make_time_duration(time_rep start, time_rep end)
      assert(CLOCKS_PER_SEC == time_duration_type::rep_type::res_adjust());
      return time_duration_type(0,0,0, end - start);

> >
> > template <class timer_traits>
> > class timer
> > {
> > public:
> > typedef timer_traits traits_type;
> > typedef typename timer_traits::time_rep time_rep;
> > typedef typename timer_traits::time_duration_type time_duration_type;
> >
> > timer ();
> I would suggest the construct would also start the timing.
> > bool is_running() const;
> I would suggest a timer always runs.

That assumption really limits the use of the timer. For example,
you can't use it in a user interface where a start/stop button
can be controlled by a user to measure the total elapsed time on
a task that might be interupted. For program timing there might be
sections of the program execution I would like to ignore. This is
not possible without a stop function.


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