Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
TimeUtils.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright © 2014-2024 Allan Leal
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library. If not, see <http://www.gnu.org/licenses/>.
17 
18 #pragma once
19 
20 // C++ includes
21 #include <chrono>
22 
23 namespace Reaktoro {
24 
25 using Time = std::chrono::time_point<std::chrono::high_resolution_clock>;
26 
27 using Duration = std::chrono::duration<double>;
28 
31 auto time() -> Time;
32 
37 auto elapsed(Time const& end, Time const& begin) -> double;
38 
42 auto elapsed(Time const& begin) -> double;
43 
45 class Stopwatch
46 {
47 public:
50 
52  auto start() -> void;
53 
55  auto pause() -> void;
56 
58  auto reset() -> void;
59 
61  auto time() const -> double;
62 
63 private:
65  Time mstart;
66 
68  double melapsed = 0.0;
69 };
70 
71 } // namespace Reaktoro
Used for measuring elapsed time since object creation.
Definition: TimeUtils.hpp:46
auto pause() -> void
Pause measuring time.
Stopwatch()
Construct a Stopwatch object and start measuring time.
auto reset() -> void
Reset the stopwatch.
auto time() const -> double
Get the accumulated elapsed time (in seconds) between calls to methods start and pause.
auto start() -> void
Start measuring time.
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
auto time() -> Time
Return the time point now.
auto elapsed(Time const &end, Time const &begin) -> double
Return the elapsed time between two time points (in units of s)