GEOS
Timer.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 Total, S.A
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_COMMON_TIMER_HPP
21 #define GEOS_COMMON_TIMER_HPP
22 
23 #include <chrono>
24 
25 namespace geos
26 {
27 
32 class Timer
33 {
34 public:
35 
40  Timer( std::chrono::system_clock::duration & duration ):
41  m_start( std::chrono::system_clock::now() ),
42  m_duration( duration )
43  {}
44 
47  { m_duration += std::chrono::system_clock::now() - m_start; }
48 
49 private:
51  std::chrono::system_clock::time_point const m_start;
53  std::chrono::system_clock::duration & m_duration;
54 };
55 
56 }
57 
58 #endif // GEOS_COMMON_TIMER_HPP
Object that times the duration of its existence.
Definition: Timer.hpp:33
Timer(std::chrono::system_clock::duration &duration)
Constructor. The time the object is alive is added to duration.
Definition: Timer.hpp:40
~Timer()
Destructor. Adds to the referenced duration.
Definition: Timer.hpp:46