43 std::chrono::high_resolution_clock::time_point start;
68 SimpleTimer(
const std::string& description,
const int& cycles_to_time = 1,
bool output =
true, std::ostream& out = std::cout)
74 , period(cycles_to_time)
78 , time_at_start_of_timing(0)
79 , timing_started(false)
89 delete internal_cvd_timer;
97 timing_started =
true;
98 time_at_start_of_timing = internal_cvd_timer->get_time();
100 else if(timing_started)
102 increment = internal_cvd_timer->get_time() - time_at_start_of_timing;
103 time_buffer.push_back(increment);
104 if((
int)time_buffer.size() > period && period > 0)
105 time_buffer.pop_front();
107 timing_started =
false;
108 if(timings % period == 0 && output_info)
119 if((
int)time_buffer.size() == 1)
120 sout << text <<
" takes: " << get_average() <<
"s over 1 timing" << std::endl;
122 sout << text <<
" takes : av " << get_average() <<
"s , max " << get_max() <<
"s, min " << get_min() <<
"s, over " << time_buffer.size() <<
" timings" << std::endl;
125 sout << text <<
" section : error. No timed cycles. Use click() to start and stop timing." << std::endl;
132 if(time_buffer.size() > 0)
133 max = time_buffer[0];
134 if(time_buffer.size() > 1)
135 for(
int i = 0; i < (int)time_buffer.size(); ++i)
136 max = std::max(time_buffer[i], max);
145 if(time_buffer.size() > 0)
146 min = time_buffer[0];
147 if(time_buffer.size() > 1)
148 for(
int i = 0; i < (int)time_buffer.size(); ++i)
149 min = std::min(time_buffer[i], min);
157 if(time_buffer.size() > 0)
160 for(
int i = 0; i < (int)time_buffer.size(); ++i)
161 cumulative_time += time_buffer[i];
162 average = cumulative_time /
static_cast<double>(time_buffer.size());
169 double max, min, average;
174 double cumulative_time;
175 double time_at_start_of_timing;
179 std::deque<double> time_buffer;
double reset()
Sets the start time to the current time.
Definition: cvd_timer.cc:30
All classes and functions are within the CVD namespace.
Definition: argb.h:6
double conv_ntime(const double &time) const
Convert current time given as double by correcting for the start time.
Definition: cvd_timer.cc:50
~SimpleTimer()
Destructor. Deletes the internal cvd_timer.
Definition: timer.h:87
void print()
Output timing information (average, maximum and minimum times for a set of cycles).
Definition: timer.h:115
double get_average()
Calculate the average cycle time as double.
Definition: timer.h:154
cvd_timer()
Create a timer, and set the start time to be now.
Definition: cvd_timer.cc:25
double get_time_of_day()
Same as the system call gettimeofday, but returns seconds since the epoch as a double.
Definition: cvd_timer.cc:45
Provides a simple timer class which uses cvd_timer internally.
Definition: timer.h:60
double get_time()
How many seconds have elapsed since the start time?
Definition: cvd_timer.cc:39
long long get_time_of_day_ns()
Same as the system call gettimeofday, but returns nanoseconds seconds since the epoch.
Definition: cvd_timer.cc:18
double get_min()
Calculate the min cycle time as double.
Definition: timer.h:142
SimpleTimer(const std::string &description, const int &cycles_to_time=1, bool output=true, std::ostream &out=std::cout)
Create a simple timer object.
Definition: timer.h:68
void click()
Begin or end a timing cycle. Automatically calls print() when cycles_to_time cycles are reached...
Definition: timer.h:93
Provides the time elapsed in seconds.
Definition: timer.h:26
double get_max()
Calculate the max cycle time as double.
Definition: timer.h:129