-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paths7c_benchmark.cpp
More file actions
81 lines (71 loc) · 1.36 KB
/
s7c_benchmark.cpp
File metadata and controls
81 lines (71 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "s7c_benchmark.hpp"
#include <iostream>
Timer::Timer(const std::string& name, bool enable) : name(name), running(enable)
{
#ifdef TIMER_DEBUG
debug("created");
#endif
if (running) start();
}
double Timer::tick()
{
if (!running)
{
#ifdef TIMER_DEBUG
debug("tried to tick while stop!");
#endif
return 0;
}
double value = std::chrono::duration<double, std::nano>(std::chrono::high_resolution_clock::now() - startT).count();
sumT += value;
#ifdef TIMER_DEBUG
debug("tick");
#endif
return value;
}
void Timer::start(bool do_reset)
{
#ifdef TIMER_DEBUG
debug("start");
#endif
if (do_reset) reset();
running = true;
startT = std::chrono::high_resolution_clock::now();
}
void Timer::stop()
{
if (!running) return;
tick();
running = false;
#ifdef TIMER_DEBUG
debug("stop");
#endif
}
void Timer::reset()
{
sumT = 0.0;
start();
#ifdef TIMER_DEBUG
debug("reset");
#endif
}
double Timer::get_sum() { return sumT; }
void Timer::print()
{
tick();
std::cout << std::fixed << name << " in " << sumT << std::endl;
}
void Timer::print_tick()
{
std::cout << std::fixed << name << " ticked in " << tick() << std::endl;
}
#ifdef TIMER_DEBUG
void Timer::debug(std::string msg)
{
std::cout << "[" << name << "] " << msg << std::endl;
}
#endif
Timer::~Timer()
{
if (running) stop();
}