21 std::cout <<
"Constructor default MyTimer "<< std::endl;
29 std::cout <<
"Constructor default MyTimer "<< std::endl;
38 std::cout <<
"Destructor MyTimer "<< std::endl;
44 std::cout <<
"MyTimer::Start " << std::endl;
52 std::cout <<
"MyTimer::Stop " << std::endl;
60 std::cout <<
"MyTimer::Reset " << str_name << std::endl;
86 std::cout <<
"MyTimer::Report " << std::endl;
89 std::cout <<
"====================" << std::endl;
90 std::cout <<
"MyTimer Report, all times in seconds" << std::endl;
92 std::cout <<
"\n Name : " <<
name << std::endl;
96 assert ( times.size() == 4);
99 std::cout.precision(6);
100 std::cout << std::setw(15) <<
"Total time" << std::setw(15) <<
"Average" << std::setw(15) <<
"Minimum" << std::setw(15) <<
"Maximum" << std::endl;
101 std::cout << std::setw(15) << times[0] << std::setw(15) << std::scientific << times[1]
102 << std::setw(15) << std::scientific << times[2] << std::setw(15) << times[3] << std::endl;
105 std::cout <<
"\n====================" << std::endl;
112 std::cout <<
"Constructor default OneTimer "<< std::endl;
125 assert (
total_t.count() == 0 );
127 assert (
start_t.time_since_epoch().count() == 0 );
128 assert (
stop_t.time_since_epoch().count() == 0 );
133 std::cout <<
"Destructor OneTimer "<< std::endl;
141 std::cout <<
"OneTimer::Start " << std::endl;
146 if ( start_t.time_since_epoch().count() != 0 ) {
147 std::cout <<
"Warning in MyTimer::Start(), maybe called 2 times " << std::endl;
148 std::cout <<
"Warning The starting time will not modified " << std::endl;
166 start_t = std::chrono::steady_clock::now();
169 std::cout <<
" start_t.time_since_epoch().count() " << start_t.time_since_epoch().count() << std::endl;
170 std::cout <<
" stop_t.time_since_epoch().count() " << stop_t.time_since_epoch().count() << std::endl;
176 std::cout <<
"OneTimer::Stop " << std::endl;
181 if ( stop_t.time_since_epoch().count() != 0 ) {
182 std::cout <<
"Warning in MyTimer::Stop(), maybe called 2 times " << std::endl;
183 std::cout <<
"Warning Stopping timer is discarded " << std::endl;
187 if ( start_t.time_since_epoch().count() == 0 ) {
188 std::cout <<
"Warning in MyTimer::Stop(), Start() has not been called " << std::endl;
189 std::cout <<
"Warning Stopping timer is discarded " << std::endl;
193 stop_t = std::chrono::steady_clock::now();
195 total_t += stop_t - start_t;
232 std::cout <<
"OneTimer::Reset " << std::endl;
242 std::vector<double> all_times;
247 all_times.push_back ( std::chrono::duration<double>(total_t).count() );
249 all_times.push_back ( std::chrono::duration<double>(total_t).count() / n_call );
252 all_times.push_back ( 0. );
254 all_times.push_back ( 0. );
unsigned int GetNumberCalls(std::string str_name=std::string("default_timer"))
Get the number of calls (used for average)
tpoint stop_t
time_point, stopping time
OneTimer()
default constructor.
void Reset(std::string str_name=std::string("default_timer"))
Reset the timer.
unsigned int n_call
number of calls to stop/start
std::vector< double > GetAllTimes()
Get all computed times.
void Stop()
Stop the timer.
tpoint start_t
time_point, starting time
MyTimer()
default constructor
std::string name
first implementation, only one name,
double GetTotalTime(std::string str_name=std::string())
Get the total time, anonymous or named.
void Stop()
Stop the timer.
unsigned int GetNumberCalls()
Get the number of calls.
void Start()
Start the timer.
virtual ~MyTimer()
virtual destructor, class could be derived
std::chrono::duration< double, std::milli > duration_dtt
duration_dtt total_t
total time, a duration
nested class of MyTimer, contains the timers functions
std::chrono::time_point< std::chrono::steady_clock, std::chrono::duration< double, std::ratio< 1, 1000000000 > > > tpoint
void Reset()
reset the timer
void Start()
Start the timer.
double GetAverageTime(std::string str_name=std::string())
Get the average time, total time / number of calls.
Define a timer class, to be used for testing performance.
virtual void Report()
Make a report for the timers.