Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2005-03-06 18:26:46


On Fri, 4 Mar 2005 23:41:10 -0700, Brian Braatz wrote
> The code I am using was originally developed by Christopher Diggins.
> His code allows for use of boost.timer or the high_resolution_timer.
>
> I am currently using the high_resolution timer.
>
> THANK YOU for the suggestion of using the microsec_time_clock.hpp. I
> did not know that existed, do you know how does this compare to the
> high_resolution timer?

Sorry to be so far behind on this thread -- I'll just add a couple thoughts
here. The microsecond timer is used to construct a posix_time::ptime instance
which represents time to microsecond/nano second resolution. The usage looks
like this:

 ptime t1 = microsec_clock::local_time(); //time in tz of computer in 1.32
 ptime t2 = microsec_clock::universal_time(); //CVS only, time in UTC

http://www.boost.org/doc/html/date_time/posix_time.html#ptime_from_clock

In date-time the idea is that clocks can be developed independent of the time
representation -- so if there is a platform specific or hardware driven clock
it can integrate with the library simply by writing an adaptor function to
constuct the time representation. Using microsecond_clock won't necessarily
solve all your timing problems as it uses FILETIME on Windows and gettimeofday
on Posix platforms.

> I need to stick to a base release version of boost for production
> reasons, do you think this other timer will work inside 1.32?
>
> Thank you very much for your thoughts, I would not have noticed the
> microsec if you had not pointed it out to me.

It's been on my todo list for awhile to replace the current boost.timer with
one based on the concepts in date-time. It's just been behind a couple major
projects related to I/O and local time representation. I've added a little
example of how the current timer could be trivially rewritten using the
date_time classes including the microsecond clock. If you need to prime the
start time you could just create another constructor that takes a start time.

 //just replacing the current timer interfaces with date-time
 //classes like time_duration and posix_time
 class timer
 {
 public:
  timer() : start_time_(boost::posix_time::microsec_clock::local_time())
    {}
  void restart()
     { start_time_ = microsec_clock::local_time(); }
  time_duration elapsed() const
     { return boost::posix_time::microsec_clock::local_time() - start_time_;}
 private:
  boost::posix_time::ptime start_time_;
 }; // timer

The prior discussions of this issue and this example can be found at:

http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?GDTL/Timer

Jeff


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