-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer_test.cpp
79 lines (67 loc) · 2.11 KB
/
timer_test.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
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
#include <iostream>
#include <chrono>
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
#include "timer.hpp"
void check(std::string test_name, const bool condition)
{
std::cout << std::move(test_name);
if (condition)
{
std::cout << "-> PASSED!\n";
}
else
{
std::cout << "-> FAILED!\n";
}
}
void check_add_tag()
{
timer_util::timer timer;
timer.add_tag("test");
check("Check adding tags...", timer.tags[0].name == "test");
}
void check_to_string()
{
timer_util::timer timer;
timer.add_tag("tag 1");
sleep(0.5);
timer.add_tag("tag 2");
sleep(0.5);
timer.add_tag("tag 3");
std::string expectedString = "";
expectedString += "tag 1: ";
expectedString += std::to_string(((std::chrono::duration<double, std::milli>)(timer.tags[0].time_point - timer.tags[0].time_point)).count());
expectedString += "ms\n";
expectedString += "tag 2: ";
expectedString += std::to_string(((std::chrono::duration<double, std::milli>)(timer.tags[1].time_point - timer.tags[0].time_point)).count());
expectedString += "ms\n";
expectedString += "tag 3: ";
expectedString += std::to_string(((std::chrono::duration<double, std::milli>)(timer.tags[2].time_point - timer.tags[1].time_point)).count());
expectedString += "ms\n";
check("Check formating data into a string...", timer.to_string() == expectedString);
}
void stress_test()
{
timer_util::timer timer;
std::uint_fast32_t insertion_count = 1000000;
auto start = std::chrono::high_resolution_clock::now();
for (std::uint_fast32_t i = 0; i < insertion_count; i++)
{
timer.add_tag("test");
}
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> required_time = end - start;
std::cout << "Performed " << insertion_count << " time point recordings.\n";
std::cout << "Time required: " << required_time.count() << "ms.\n";
std::cout << "Averages to " << required_time.count() / insertion_count << "ms per recording.\n";
}
int main()
{
check_add_tag();
check_to_string();
stress_test();
}