Biorbd Release_1.13.0
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
7using namespace BIORBD_NAMESPACE;
8
10 : m_timers(std::map<utils::String, utils::Timer>()),
11 m_counts(std::map<utils::String, int>()) {}
12
13void 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
22 return m_timers[name].getLap();
23}
24
26 return m_timers[name].stop();
27}
28
30 m_timers[name].pause();
31}
32
34 m_timers[name].resume();
35}
36
38 ++(m_counts[name]);
39}
40
42 return m_counts[name];
43}
44
45void 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}
void resumeTimer(const String &name)
Resume a timer of a specified name.
Definition Benchmark.cpp:33
Benchmark()
Construct a benchmark analysis.
Definition Benchmark.cpp:9
static void wasteTime(double timeInSec)
To waste time (similar to a sleep function).
Definition Benchmark.cpp:45
std::map< String, Timer > m_timers
Timers.
Definition Benchmark.h:81
std::map< String, int > m_counts
Counts.
Definition Benchmark.h:82
double stopTimer(const String &name)
Stop the timer of a specified name and get lap time.
Definition Benchmark.cpp:25
void addTimer(const String &name)
Add a new timer to the timer set.
Definition Benchmark.cpp:37
double getLap(const String &name)
Get lap time of a specified timer.
Definition Benchmark.cpp:21
int getTimerIdx(const String &name)
Get the index of the specified timer.
Definition Benchmark.cpp:41
void pauseTimer(const String &name)
Pause a timer of a specified name.
Definition Benchmark.cpp:29
void startTimer(const String &name, bool force=false)
Start the timer of a specified name.
Definition Benchmark.cpp:13
Wrapper around the std::string class with augmented functionality.
Definition String.h:18
Wrapper around timer function in C++.
Definition Timer.h:15