Biorbd
Release_1.13.0
Toggle main menu visibility
Loading...
Searching...
No Matches
Benchmark.cpp
1
#define BIORBD_API_EXPORTS
2
#include "Utils/Benchmark.h"
3
4
#include "Utils/String.h"
5
#include "Utils/Timer.h"
6
7
using namespace
BIORBD_NAMESPACE;
8
9
utils::Benchmark::Benchmark
()
10
:
m_timers
(std::map<utils::
String
, utils::
Timer
>()),
11
m_counts
(std::map<utils::
String
, int>()) {}
12
13
void
utils::Benchmark::startTimer
(
const
utils::String
& name,
bool
force) {
14
if
(force) {
15
m_timers
[name].start();
16
}
else
if
(!
m_timers
[name].isStarted()) {
17
m_timers
[name].start();
18
}
19
}
20
21
double
utils::Benchmark::getLap
(
const
utils::String
& name) {
22
return
m_timers
[name].getLap();
23
}
24
25
double
utils::Benchmark::stopTimer
(
const
utils::String
& name) {
26
return
m_timers
[name].stop();
27
}
28
29
void
utils::Benchmark::pauseTimer
(
const
utils::String
& name) {
30
m_timers
[name].pause();
31
}
32
33
void
utils::Benchmark::resumeTimer
(
const
utils::String
& name) {
34
m_timers
[name].resume();
35
}
36
37
void
utils::Benchmark::addTimer
(
const
utils::String
& name) {
38
++(
m_counts
[name]);
39
}
40
41
int
utils::Benchmark::getTimerIdx
(
const
utils::String
& name) {
42
return
m_counts
[name];
43
}
44
45
void
utils::Benchmark::wasteTime
(
double
seconds) {
46
// Wait for seconds ask doing dummy stuff
47
48
std::clock_t start(std::clock());
49
50
while
(((
static_cast<
double
>
(std::clock() - start)) / CLOCKS_PER_SEC) <
51
seconds) {
52
}
53
}
BIORBD_NAMESPACE::utils::Benchmark::resumeTimer
void resumeTimer(const String &name)
Resume a timer of a specified name.
Definition
Benchmark.cpp:33
BIORBD_NAMESPACE::utils::Benchmark::Benchmark
Benchmark()
Construct a benchmark analysis.
Definition
Benchmark.cpp:9
BIORBD_NAMESPACE::utils::Benchmark::wasteTime
static void wasteTime(double timeInSec)
To waste time (similar to a sleep function).
Definition
Benchmark.cpp:45
BIORBD_NAMESPACE::utils::Benchmark::m_timers
std::map< String, Timer > m_timers
Timers.
Definition
Benchmark.h:81
BIORBD_NAMESPACE::utils::Benchmark::m_counts
std::map< String, int > m_counts
Counts.
Definition
Benchmark.h:82
BIORBD_NAMESPACE::utils::Benchmark::stopTimer
double stopTimer(const String &name)
Stop the timer of a specified name and get lap time.
Definition
Benchmark.cpp:25
BIORBD_NAMESPACE::utils::Benchmark::addTimer
void addTimer(const String &name)
Add a new timer to the timer set.
Definition
Benchmark.cpp:37
BIORBD_NAMESPACE::utils::Benchmark::getLap
double getLap(const String &name)
Get lap time of a specified timer.
Definition
Benchmark.cpp:21
BIORBD_NAMESPACE::utils::Benchmark::getTimerIdx
int getTimerIdx(const String &name)
Get the index of the specified timer.
Definition
Benchmark.cpp:41
BIORBD_NAMESPACE::utils::Benchmark::pauseTimer
void pauseTimer(const String &name)
Pause a timer of a specified name.
Definition
Benchmark.cpp:29
BIORBD_NAMESPACE::utils::Benchmark::startTimer
void startTimer(const String &name, bool force=false)
Start the timer of a specified name.
Definition
Benchmark.cpp:13
BIORBD_NAMESPACE::utils::String
Wrapper around the std::string class with augmented functionality.
Definition
String.h:18
BIORBD_NAMESPACE::utils::Timer
Wrapper around timer function in C++.
Definition
Timer.h:15
src
Utils
Benchmark.cpp
Generated by
1.18.0