epoc32/include/stdapis/boost/timer.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
//  boost timer.hpp header file  ---------------------------------------------//
williamr@2
     2
williamr@2
     3
//  Copyright Beman Dawes 1994-99.  Distributed under the Boost
williamr@2
     4
//  Software License, Version 1.0. (See accompanying file
williamr@2
     5
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
williamr@2
     6
williamr@2
     7
//  See http://www.boost.org/libs/timer for documentation.
williamr@2
     8
williamr@2
     9
//  Revision History
williamr@2
    10
//  01 Apr 01  Modified to use new <boost/limits.hpp> header. (JMaddock)
williamr@2
    11
//  12 Jan 01  Change to inline implementation to allow use without library
williamr@2
    12
//             builds. See docs for more rationale. (Beman Dawes) 
williamr@2
    13
//  25 Sep 99  elapsed_max() and elapsed_min() added (John Maddock)
williamr@2
    14
//  16 Jul 99  Second beta
williamr@2
    15
//   6 Jul 99  Initial boost version
williamr@2
    16
williamr@2
    17
#ifndef BOOST_TIMER_HPP
williamr@2
    18
#define BOOST_TIMER_HPP
williamr@2
    19
williamr@2
    20
#include <boost/config.hpp>
williamr@2
    21
#include <ctime>
williamr@2
    22
#include <boost/limits.hpp>
williamr@2
    23
williamr@2
    24
# ifdef BOOST_NO_STDC_NAMESPACE
williamr@2
    25
    namespace std { using ::clock_t; using ::clock; }
williamr@2
    26
# endif
williamr@2
    27
williamr@2
    28
williamr@2
    29
namespace boost {
williamr@2
    30
williamr@2
    31
//  timer  -------------------------------------------------------------------//
williamr@2
    32
williamr@2
    33
//  A timer object measures elapsed time.
williamr@2
    34
williamr@2
    35
//  It is recommended that implementations measure wall clock rather than CPU
williamr@2
    36
//  time since the intended use is performance measurement on systems where
williamr@2
    37
//  total elapsed time is more important than just process or CPU time.
williamr@2
    38
williamr@2
    39
//  Warnings: The maximum measurable elapsed time may well be only 596.5+ hours
williamr@2
    40
//  due to implementation limitations.  The accuracy of timings depends on the
williamr@2
    41
//  accuracy of timing information provided by the underlying platform, and
williamr@2
    42
//  this varies a great deal from platform to platform.
williamr@2
    43
williamr@2
    44
class timer
williamr@2
    45
{
williamr@2
    46
 public:
williamr@2
    47
         timer() { _start_time = std::clock(); } // postcondition: elapsed()==0
williamr@2
    48
//         timer( const timer& src );      // post: elapsed()==src.elapsed()
williamr@2
    49
//        ~timer(){}
williamr@2
    50
//  timer& operator=( const timer& src );  // post: elapsed()==src.elapsed()
williamr@2
    51
  void   restart() { _start_time = std::clock(); } // post: elapsed()==0
williamr@2
    52
  double elapsed() const                  // return elapsed time in seconds
williamr@2
    53
    { return  double(std::clock() - _start_time) / CLK_TCK; }
williamr@2
    54
williamr@2
    55
  double elapsed_max() const   // return estimated maximum value for elapsed()
williamr@2
    56
  // Portability warning: elapsed_max() may return too high a value on systems
williamr@2
    57
  // where std::clock_t overflows or resets at surprising values.
williamr@2
    58
  {
williamr@2
    59
    return (double((std::numeric_limits<std::clock_t>::max)())
williamr@2
    60
       - double(_start_time)) / double(CLK_TCK); 
williamr@2
    61
  }
williamr@2
    62
williamr@2
    63
  double elapsed_min() const            // return minimum value for elapsed()
williamr@2
    64
   { return double(1)/double(CLK_TCK); }
williamr@2
    65
williamr@2
    66
 private:
williamr@2
    67
  std::clock_t _start_time;
williamr@2
    68
}; // timer
williamr@2
    69
williamr@2
    70
} // namespace boost
williamr@2
    71
williamr@2
    72
#endif  // BOOST_TIMER_HPP