Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Class timer

boost::log::attributes::timer — A class of an attribute that makes an attribute value of the time interval since construction.


// In header: <boost/log/attributes/timer.hpp>

class timer : public attribute {
  // types
  typedef utc_time_traits::time_type::time_duration_type value_type;  // Attribute value type. 

  // construct/copy/destruct
  explicit timer(cast_source const &);


The timer attribute calculates the time passed since its construction and returns it on value acquisition. The attribute value type is boost::posix_time::time_duration.

On Windows platform there are two implementations of the attribute. The default one is more precise but a bit slower. This version uses QueryPerformanceFrequence/QueryPerformanceCounter API to calculate elapsed time.

There are known problems with these functions when used with some CPUs, notably AMD Athlon with Cool'n'Quiet technology enabled. See the following links for more information and possible resolutions:;en-us;895980

In case if none of these solutions apply, you are free to define BOOST_LOG_NO_QUERY_PERFORMANCE_COUNTER macro to fall back to another implementation based on Boost.DateTime.

timer public construct/copy/destruct

  1. timer();

    Constructor. Starts time counting.

  2. explicit timer(cast_source const & source);

    Constructor for casting support