BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
WallclockTimer.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Fit/Tools/WallclockTimer.cpp
6 //! @brief Implements class WallclockTimer.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
16 #include <chrono>
17 
18 using clock_used = std::chrono::high_resolution_clock;
19 using duration_unit = std::chrono::seconds;
20 
21 //! Internal state of a WallclockTimer object.
22 
24  std::chrono::time_point<clock_used> m_start_time;
25  std::chrono::time_point<clock_used> m_end_time;
26  bool m_is_running{false};
27 };
28 
31 
33 {
34  m_state->m_is_running = true;
35  m_state->m_start_time = clock_used::now();
36 }
37 
39 {
40  m_state->m_is_running = false;
41  m_state->m_end_time = clock_used::now();
42 }
43 
45 {
46  duration_unit diff =
47  m_state->m_is_running
48  ? std::chrono::duration_cast<duration_unit>(clock_used::now() - m_state->m_start_time)
49  : std::chrono::duration_cast<duration_unit>(m_state->m_end_time
50  - m_state->m_start_time);
51 
52  return (double)diff.count();
53 }
std::chrono::high_resolution_clock clock_used
std::chrono::seconds duration_unit
Defines WallclockTimer class.
double runTime() const
returns run time in sec.
std::unique_ptr< WallclockTimerState > m_state
Internal state of a WallclockTimer object.
std::chrono::time_point< clock_used > m_end_time
std::chrono::time_point< clock_used > m_start_time