]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/multiprecision/test/timer.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / multiprecision / test / timer.hpp
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
6
7 #include <ctime>
8 #include <limits>
9
10 //
11 // This file archives the old (now deprecated) Boost.Timer.
12 // It is however, all that we need for a simple timeout.
13 //
14 // TODO: replace with std::chrono once we remove C++03
15 // support in 2021.
16 //
17
18 class timer
19 {
20 public:
21 timer() { _start_time = std::clock(); } // postcondition: elapsed()==0
22 // timer( const timer& src ); // post: elapsed()==src.elapsed()
23 // ~timer(){}
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
27 {
28 return double(std::clock() - _start_time) / CLOCKS_PER_SEC;
29 }
30
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.
34 {
35 return (double((std::numeric_limits<std::clock_t>::max)()) - double(_start_time)) / double(CLOCKS_PER_SEC);
36 }
37
38 double elapsed_min() const // return minimum value for elapsed()
39 {
40 return double(1) / double(CLOCKS_PER_SEC);
41 }
42
43 private:
44 std::clock_t _start_time;
45 }; // timer