LDMX Software
Timer.h
1#ifndef FRAMEWORK_PERFORMANCE_TIMER
2#define FRAMEWORK_PERFORMANCE_TIMER
3
4#include <Rtypes.h> // For ClassDef
5
6#include <chrono>
7#include <string>
8
9#include "TDirectory.h"
10
11namespace framework::performance {
12
39class Timer {
40 using clock = std::chrono::high_resolution_clock;
47 std::chrono::time_point<clock> begin_;
48
55 std::chrono::time_point<clock> end_;
56
62 long int start_time_{-1};
63
73 double duration_{-1};
74
75 public:
77 Timer() = default;
79 virtual ~Timer() = default;
81 void reset();
83 void start();
85 void stop();
87 double duration() const;
97 void write(TDirectory* location, const std::string& name) const;
98 ClassDef(Timer, 2);
99};
100
101} // namespace framework::performance
102
103#endif
Time how long a specific operation takes and serialize the result with ROOT.
Definition Timer.h:39
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_
transient
Definition Timer.h:62
double duration_
Length of time recorded by the timer in seconds.
Definition Timer.h:73
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_
transient
Definition Timer.h:55
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