GEOSX
Stopwatch.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 Total, S.A
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
19 #ifndef GEOSX_STOPWATCH_HPP
20 #define GEOSX_STOPWATCH_HPP
21 
22 #include <chrono>
23 
24 namespace geosx
25 {
26 
31 class Stopwatch
32 {
33 public:
34 
39  {
40  zero();
41  }
42 
46  void zero()
47  {
48  m_start = std::chrono::steady_clock::now();
49  }
50 
56  {
57  std::chrono::steady_clock::time_point const end = std::chrono::steady_clock::now();
58  std::chrono::duration< real64 > const diff = end - m_start;
59  return diff.count();
60  }
61 
62 private:
63 
65  std::chrono::steady_clock::time_point m_start;
66 };
67 
68 } // end geosx
69 
70 #endif
real64 elapsedTime()
Return elapsed time in seconds since zero() was last called.
Definition: Stopwatch.hpp:55
void zero()
Zero out the timer.
Definition: Stopwatch.hpp:46
Stopwatch()
Constructor.
Definition: Stopwatch.hpp:38
double real64
64-bit floating point type.
Definition: DataTypes.hpp:136
Class defining a simple stopwatch for interval timing.
Definition: Stopwatch.hpp:31