STORMM Source Documentation
Loading...
Searching...
No Matches
stopwatch.h
1// -*-c++-*-
2#ifndef STORMM_BENCHMARK_TEST_H
3#define STORMM_BENCHMARK_TEST_H
4
5#include <string>
6#include <vector>
7#include "copyright.h"
8#include "Constants/behavior.h"
9
10namespace stormm {
11namespace testing {
12
13using constants::ExceptionResponse;
14
23class StopWatch {
24public:
25
31 StopWatch(const std::string &title_in = std::string("Timer"));
32
34 ~StopWatch() = default;
35
42 StopWatch(const StopWatch &original) = default;
43 StopWatch(StopWatch &&original) = default;
44 StopWatch& operator=(const StopWatch &original) = default;
45 StopWatch& operator=(StopWatch &&original) = default;
47
49 double getTimeAtStart() const;
50
55 double getTimeAtLastTest() const;
56
58 double getTimeSinceStart() const;
59
62 double getTimeSinceLastTest() const;
63
73 double getCategoryDuration(int query_index) const;
74 double getCategoryDuration(const std::string &query_name) const;
76
86 double getCategoryAverageInterval(int query_index) const;
87 double getCategoryAverageInterval(const std::string &query_name) const;
89
99 double getCategoryMinimumTime(int query_index) const;
100 double getCategoryMinimumTime(const std::string &query_name) const;
102
112 double getCategoryMaximumTime(int query_index) const;
113 double getCategoryMaximumTime(const std::string &query_name) const;
115
125 int getCategorySamples(int query_index) const;
126 int getCategorySamples(const std::string &query_name) const;
128
132 std::string getCategoryName(int query_index) const;
133
139 int getCategoryIndex(const std::string &query,
140 ExceptionResponse policy = ExceptionResponse::DIE) const;
141
143 double getTotalDuration() const;
144
158 void assignTime(int target, double reference_time);
159 void assignTime(int target = 0);
160 void assignTime(const std::string &target);
161 void assignTime(const std::string &target, double reference_time);
163
168 int addCategory(const std::string &name);
169
175 void printResults(double precision = 1.0e6);
176
193 double2 timeDifferential(const std::string &catg_a, const std::string &catg_b,
194 const std::string &referring_function = std::string("")) const;
195
196 double2 timeDifferential(int catg_a, int catg_b,
197 const std::string &referring_function = std::string("")) const;
199
200private:
201 int category_count;
202 double initial_time;
203 double time_at_last_test;
205 std::vector<double> category_start_times;
206 std::vector<double> category_total_times;
207 std::vector<double> category_squared_times;
209 std::vector<double> category_last_times;
210 std::vector<double> category_min_interval;
211 std::vector<double> category_max_interval;
212 std::vector<int> category_samples;
214 std::vector<std::string> category_names;
215 std::string label;
216
218 double translateCurrentTime() const;
219
225 double2 computeDifferential(int catg_a, int catg_b) const;
226
231 void validateCategoryIndex(int index, const std::string &referring_function) const;
232
238 int validateCategoryName(const std::string &query, const std::string &referring_function) const;
239};
240
241} // namespace testing
242} // namespace stormm
243
244#endif
StopWatch(const std::string &title_in=std::string("Timer"))
The basic constructor records the time at which initialization was called and creates a section calle...
Definition stopwatch.cpp:25
double getCategoryDuration(int query_index) const
Get the duration recorded under any one category.
Definition stopwatch.cpp:75
double getTimeSinceStart() const
Get the time since this StopWatch was first started.
Definition stopwatch.cpp:65
double getTimeAtStart() const
Get the time at which this StopWatch was first started.
Definition stopwatch.cpp:55
~StopWatch()=default
Default destructor.
void assignTime(int target, double reference_time)
Assign an amount of time to this StopWatch.
Definition stopwatch.cpp:159
double2 timeDifferential(const std::string &catg_a, const std::string &catg_b, const std::string &referring_function=std::string("")) const
Obtain the time taken as the difference of two categories, catg_a - catg_b. The result is returned as...
Definition stopwatch.cpp:290
int getCategorySamples(int query_index) const
Get the maximum stretch of time recorded under any one category.
Definition stopwatch.cpp:119
std::string getCategoryName(int query_index) const
Get the name of a timing category based on its index in the program.
Definition stopwatch.cpp:130
double getCategoryAverageInterval(int query_index) const
Get the average interval of time observed for any given category.
Definition stopwatch.cpp:86
double getCategoryMaximumTime(int query_index) const
Get the maximum stretch of time recorded under any one category.
Definition stopwatch.cpp:108
StopWatch(const std::string &title_in=std::string("Timer"))
The basic constructor records the time at which initialization was called and creates a section calle...
Definition stopwatch.cpp:25
int addCategory(const std::string &name)
Add a section to the current StopWatch, if no such section already exists. Return the index of the se...
Definition stopwatch.cpp:193
double getTotalDuration() const
Report the total duration recorded by this stopwatch under all sections.
Definition stopwatch.cpp:154
StopWatch(const StopWatch &original)=default
With no const members or points to repair, the default copy and move constructors,...
double getTimeAtLastTest() const
Get the time at which this StopWatch last recorded a test (this is not necessarily the last time this...
Definition stopwatch.cpp:60
int getCategoryIndex(const std::string &query, ExceptionResponse policy=ExceptionResponse::DIE) const
Get the index of category based on its name. Returns -1 or an error if the named category is not pres...
Definition stopwatch.cpp:136
double getTimeSinceLastTest() const
Get the time since this StopWatch was last tested (see above for lengthier explanation).
Definition stopwatch.cpp:70
double getCategoryMinimumTime(int query_index) const
Get the minimum stretch of time recorded under any one category.
Definition stopwatch.cpp:98
void printResults(double precision=1.0e6)
Print the timings for this StopWatch.
Definition stopwatch.cpp:212
Definition stormm_vector_types.h:112