-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
51 lines (41 loc) · 1.14 KB
/
main.cpp
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
#include <thread>
#include <chrono>
#include "scope_timer.hpp"
// Just take some time, for testing purposes
void fetch_data_mock(int ms) {
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
}
// To simplify the code in this example
using ScopeTimer = GlobalTimerData::ScopeTimer;
int main() {
{ ScopeTimer empty1("empty1"); }
{ ScopeTimer empty2("empty2"); }
{
// Measure the time spent on one activity
ScopeTimer for_loop("for loop time");
volatile int count = 1;
for( int i = 0; i < 100; ++i) {
count += count;
}
}
// Use the same timer to measure two separate events
{
ScopeTimer data_fetching("data fetching");
fetch_data_mock(100);
}
{
// This timer will add to the previous "data fetching" timer
ScopeTimer data_fetching("data fetching");
fetch_data_mock(250);
}
{
// Timing an empty scope measures
// how much time the creation of
// a raii_timer adds to the measures
// (this is an error introduced by the
// measurement code)
ScopeTimer empty_scope("error margin");
}
std::cout << GlobalTimerData::get() << std::endl;
return 0;
}