Go to the documentation of this file.
39 auto start_time = std::chrono::high_resolution_clock::now();
41 Bucket& b = timers_[
str];
43 b.maybe_start = start_time;
48 auto stop_time = std::chrono::high_resolution_clock::now();
50 auto it = timers_.find(
str);
52 Bucket& b = it->second;
54 std::chrono::duration<double> diff = stop_time - *b.maybe_start;
55 b.maybe_start.reset();
56 double d = diff.count();
77 std::map<std::string, StopwatchStats>
getStats() {
78 std::map<std::string, StopwatchStats> stats_vec;
79 for (
auto const& bucket : timers_) {
81 stats.
mean = bucket.second.sum / bucket.second.num;
82 stats.
num = bucket.second.num;
83 stats.
min = bucket.second.min;
84 stats.
max = bucket.second.max;
85 stats_vec.insert({bucket.first, stats});
92 for (
auto const& stats :
getStats()) {
93 std::cout << stats.first <<
" mean time: " << stats.second.mean
94 <<
" min time: " << stats.second.min
95 <<
" max time: " << stats.second.max
96 <<
" num: " << stats.second.num << std::endl;
103 std::optional<std::chrono::time_point<std::chrono::high_resolution_clock>>
109 double max = std::numeric_limits<double>::lowest();
112 std::map<std::string, Bucket> timers_;
Definition: backtrace.cpp:102
Stopwatch class for creating multiple, optionally concurrent, timers.
Definition: stopwatch.h:28
Stopwatch for a single, named timer.
Definition: stopwatch.h:116
Container for statistics on stopwatch timers.
Definition: stopwatch.h:69
double max
Definition: stopwatch.h:72
str
Definition: event_service.py:547
auto min(TPoint const &a, TPoint const &b) -> TPoint
Definition: vector_space.h:104
#define FARM_ASSERT(condition,...)
If condition is false, Print formatted error message and then panic.
Definition: logger.h:264
double min
Definition: stopwatch.h:71
std::map< std::string, StopwatchStats > getStats()
Return container of stopwatch timer statistics.
Definition: stopwatch.h:77
double mean
Definition: stopwatch.h:70
auto sum(Expected< A > maybe_left, Expected< A > maybe_right) -> Expected< A >
Definition: expected_test.cpp:98
int num
Definition: stopwatch.h:73
void start(std::string str)
Start a new, named timer.
Definition: stopwatch.h:38
double stop(std::string str)
Stops the named timer and returns the duration.
Definition: stopwatch.h:47
auto max(TPoint const &a, TPoint const &b) -> TPoint
Definition: vector_space.h:114
~ScopedTimer()
Destructor that returns the timer duration.
Definition: stopwatch.h:123
static StopwatchSingleton & getInstance()
Returns an instance of the stopwatch timer.
Definition: stopwatch.h:31
ScopedTimer(std::string str)
Default constructor, requires timer name.
Definition: stopwatch.h:118
void print()
Prints statistics of stopwatch timers.
Definition: stopwatch.h:91