code_profiler
loop_timer.cpp
Go to the documentation of this file.
2 
3 #include <stdlib.h>
4 #include <exception>
5 
6 namespace tue
7 {
8 
9 LoopTimer::LoopTimer(): counts_(0), sum_(0.0), c_(0.0)
10 {
11 }
12 
14 {
15  ++counts_;
16  if (!total_timer_.running())
18  timer_.start();
19 }
20 
22 {
23  timer_.stop();
24  long double time = timer_.getElapsedTime();
25  long double y = time - c_;
26  long double x = sum_ + y;
27  c_ = ( x - sum_ ) - y;
28  sum_ = x;
29 }
30 
32 {
34  timer_.stop();
35  counts_ = 0;
36  sum_ = 0.0;
37  c_ = 0.0;
38 }
39 
41 {
42  if (timer_.running())
43  this->stop();
44 
45  return sum_;
46 }
47 
48 long double LoopTimer::getTotalLoopTime() const
49 {
50  if (timer_.running())
51  return sum_;
52 
53  return sum_;
54 }
55 
57 {
58  if (timer_.running())
59  this->stop();
60 
61  return sum_/counts_;
62 }
63 
64 long double LoopTimer::getAverageLoopTime() const
65 {
66  if (timer_.running())
67  return sum_/std::max<int>(counts_ - 1, 1);
68 
69  return sum_/counts_;
70 }
71 
72 
73 long double LoopTimer::getTotalTime() const
74 {
76 }
77 
79 {
80  return getTotalLoopTime()/getTotalTime();
81 }
82 
84 {
85  return getTotalLoopTime()/getTotalTime();
86 }
87 
88 }
89 
tue::Timer::getElapsedTime
long double getElapsedTime() const
Alias of Timer::getElapsedTimeInSec.
Definition: timer.cpp:107
exception
tue::Timer::running
bool running() const
Get running status of the timer.
Definition: timer.h:43
tue::LoopTimer::getTotalTime
long double getTotalTime() const
Get the total elapsed time since the first start.Stops the current iteration when running.
Definition: loop_timer.cpp:73
tue::LoopTimer::getAverageLoopTime
long double getAverageLoopTime()
Get average time per loop iteration. Stops the current iteration when running.
Definition: loop_timer.cpp:56
tue::LoopTimer::reset
void reset()
Stop the timer and reset all counters to zero.
Definition: loop_timer.cpp:31
tue::LoopTimer::counts_
long unsigned int counts_
loop counter
Definition: loop_timer.h:20
tue::Timer::stop
void stop()
Definition: timer.cpp:61
tue::LoopTimer::getTotalLoopTime
long double getTotalLoopTime()
Get total elapsed time during the loops. Stops the current iteration when running.
Definition: loop_timer.cpp:40
tue::Timer::start
void start()
Definition: timer.cpp:51
tue::LoopTimer::getLoopUsagePercentage
double getLoopUsagePercentage()
Get average percentage of total time used by the loop.
Definition: loop_timer.cpp:78
loop_timer.h
tue::LoopTimer::total_timer_
tue::Timer total_timer_
Definition: loop_timer.h:15
tue::LoopTimer::stop
void stop()
Definition: loop_timer.cpp:21
tue::LoopTimer::sum_
long double sum_
Sum so far.
Definition: loop_timer.h:25
tue::LoopTimer::c_
long double c_
Compensation for lost low-order bits.
Definition: loop_timer.h:30
tue::LoopTimer::LoopTimer
LoopTimer()
Definition: loop_timer.cpp:9
tue::LoopTimer::timer_
tue::Timer timer_
Definition: loop_timer.h:14
tue
Definition: loop_timer.h:8
tue::LoopTimer::start
void start()
Definition: loop_timer.cpp:13