LDMX Software
Timer.h
1#ifndef FRAMEWORK_PERFORMANCE_TIMER
2#define FRAMEWORK_PERFORMANCE_TIMER
3
4#include <chrono>
5#include <string>
6
7#include "TDirectory.h"
8#include "TObject.h"
9
10namespace framework::performance {
11
38class Timer {
39 using clock = std::chrono::high_resolution_clock;
47 std::chrono::time_point<clock> begin_;
48
56 std::chrono::time_point<clock> end_;
57
63 long int start_time_{-1};
64
74 double duration_{-1};
75
76 public:
78 Timer() = default;
80 virtual ~Timer() = default;
82 void reset();
84 void start();
86 void stop();
88 double duration() const;
98 void write(TDirectory* location, const std::string& name) const;
99 ClassDef(Timer, 1);
100};
101
102} // namespace framework::performance
103
104#endif
Time how long a specific operation takes and serialize the result with ROOT.
Definition Timer.h:38
void reset()
reset a timer to un-started state without re-allocating
Definition Timer.cxx:8
void write(TDirectory *location, const std::string &name) const
Write ourselves under the input name to the input location.
Definition Timer.cxx:29
virtual ~Timer()=default
create defualt destructor
long int start_time_
Time stamp for when timer was started in nanoseconds since UNIX epoch.
Definition Timer.h:63
double duration_
Length of time recorded by the timer in seconds.
Definition Timer.h:74
void stop()
stop the timer
Definition Timer.cxx:22
double duration() const
retrieve the value of the duration in seconds
Definition Timer.cxx:27
void start()
start the timer
Definition Timer.cxx:15
std::chrono::time_point< clock > end_
The time_point when the timer is stopped.
Definition Timer.h:56
std::chrono::time_point< clock > begin_
The time_point when the timer is started.
Definition Timer.h:47
Timer()=default
create a timer but don't start it yet