code_profiler
test
test_loop_timer.cpp
Go to the documentation of this file.
1
#include <
tue/profiling/loop_timer.h
>
2
3
class
LoopTimerTest
4
{
5
tue::LoopTimer
lt1_
,
lt2_
,
lt3_
;
6
tue::Timer
timer_
;
7
uint
n_
;
8
double
tot_
;
9
10
public
:
11
LoopTimerTest
(uint n):
n_
(n),
tot_
(0.0)
12
{}
13
14
void
run
( )
15
{
16
lt1_
.
start
();
17
18
for
(uint i = 0; i <
n_
; ++i)
19
{
20
lt2_
.
start
();
21
22
for
(uint j = 0; j <
n_
; ++j )
23
{
24
timer_
.
start
();
25
timer_
.
stop
();
26
tot_
+=
timer_
.
getElapsedTime
();
27
lt3_
.
start
();
28
lt3_
.
stop
();
29
}
30
31
lt2_
.
stop
();
32
}
33
34
lt3_
.
stop
();
35
}
36
37
void
printResults
()
38
{
39
std::cout
<<
"Total times using Kahan summation over "
<<
n_
*
n_
<<
" loops: "
40
<<
"\n\ttimer1: "
<<
lt1_
.
getTotalLoopTime
()*1e3 <<
" ms"
41
<<
"\n\ttimer2: "
<<
lt2_
.
getTotalLoopTime
()*1e3 <<
" ms"
42
<<
"\n\ttimer3: "
<<
lt3_
.
getTotalLoopTime
()*1e3 <<
" ms"
43
<<
"\n"
<<
std::endl
;
44
45
std::cout
<<
"tue::timer total time: "
<<
tot_
*1e3 <<
" ms (without numerical error compensation)\n"
<<
std::endl
;
46
47
std::cout
<<
"Average times using Kahan summation over "
<<
n_
*
n_
<<
" loops: "
48
<<
"\n\ttimer1: "
<<
lt1_
.
getAverageLoopTime
()*1e3 <<
" ms"
49
<<
"\n\ttimer2: "
<<
lt2_
.
getAverageLoopTime
()*1e3 <<
" ms"
50
<<
"\n\ttimer3: "
<<
lt3_
.
getAverageLoopTime
()*1e3 <<
" ms"
51
<<
"\n"
<<
std::endl
;
52
53
std::cout
<<
"tue::timer average time: "
<<
tot_
/(
n_
*
n_
)*1e3 <<
" ms (without numerical error compensation)\n"
<<
std::endl
;
54
}
55
};
56
57
int
main
()
58
{
59
LoopTimerTest
ltt(1000);
60
61
ltt.
run
();
62
63
ltt.
printResults
();
64
65
return
0;
66
}
tue::Timer::getElapsedTime
long double getElapsedTime() const
Alias of Timer::getElapsedTimeInSec.
Definition:
timer.cpp:107
LoopTimerTest::printResults
void printResults()
Definition:
test_loop_timer.cpp:37
tue::LoopTimer::getAverageLoopTime
long double getAverageLoopTime()
Get average time per loop iteration. Stops the current iteration when running.
Definition:
loop_timer.cpp:56
LoopTimerTest::timer_
tue::Timer timer_
Definition:
test_loop_timer.cpp:6
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
std::cout
LoopTimerTest::LoopTimerTest
LoopTimerTest(uint n)
Definition:
test_loop_timer.cpp:11
LoopTimerTest
Definition:
test_loop_timer.cpp:3
LoopTimerTest::lt1_
tue::LoopTimer lt1_
Definition:
test_loop_timer.cpp:5
loop_timer.h
LoopTimerTest::lt3_
tue::LoopTimer lt3_
Definition:
test_loop_timer.cpp:5
LoopTimerTest::tot_
double tot_
Definition:
test_loop_timer.cpp:8
tue::Timer
Definition:
timer.h:30
LoopTimerTest::run
void run()
Definition:
test_loop_timer.cpp:14
std::endl
T endl(T... args)
LoopTimerTest::n_
uint n_
Definition:
test_loop_timer.cpp:7
main
int main()
Definition:
test_loop_timer.cpp:57
tue::LoopTimer::stop
void stop()
Definition:
loop_timer.cpp:21
LoopTimerTest::lt2_
tue::LoopTimer lt2_
Definition:
test_loop_timer.cpp:5
tue::LoopTimer
Definition:
loop_timer.h:11
tue::LoopTimer::start
void start()
Definition:
loop_timer.cpp:13
Generated on Sun Feb 23 2025 04:33:26 for code_profiler by
1.8.17