1 ///////////////////////////////////////////////////////////////
2 // Copyright Beman Dawes 1994-99.
3 // Copyright 2020 John Maddock. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
11 // This file archives the old (now deprecated) Boost.Timer.
12 // It is however, all that we need for a simple timeout.
14 // TODO: replace with std::chrono once we remove C++03
21 timer() { _start_time = std::clock(); } // postcondition: elapsed()==0
22 // timer( const timer& src ); // post: elapsed()==src.elapsed()
24 // timer& operator=( const timer& src ); // post: elapsed()==src.elapsed()
25 void restart() { _start_time = std::clock(); } // post: elapsed()==0
26 double elapsed() const // return elapsed time in seconds
28 return double(std::clock() - _start_time) / CLOCKS_PER_SEC;
31 double elapsed_max() const // return estimated maximum value for elapsed()
32 // Portability warning: elapsed_max() may return too high a value on systems
33 // where std::clock_t overflows or resets at surprising values.
35 return (double((std::numeric_limits<std::clock_t>::max)()) - double(_start_time)) / double(CLOCKS_PER_SEC);
38 double elapsed_min() const // return minimum value for elapsed()
40 return double(1) / double(CLOCKS_PER_SEC);
44 std::clock_t _start_time;