-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclocks_test.cpp
70 lines (58 loc) · 2.36 KB
/
clocks_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
// (c) 2013 Andrey Upadyshev aka oliora <[email protected]>.
// File released to public domain.
#include "common.h"
namespace std { namespace chrono {
template<class _Elem, class _Traits, class _Clock, class _Duration>
std::basic_ostream<_Elem, _Traits> & operator<< (std::basic_ostream<_Elem, _Traits>& os, const time_point<_Clock, _Duration>& tp)
{
os << tp.time_since_epoch().count();
return os;
}
}}
namespace boost { namespace chrono {
template<class _Elem, class _Traits, class _Clock, class _Duration>
std::basic_ostream<_Elem, _Traits> & operator<< (std::basic_ostream<_Elem, _Traits>& os, const time_point<_Clock, _Duration>& tp)
{
os << tp.time_since_epoch().count();
return os;
}
}}
using namespace chrono_test;
namespace
{
template<typename T>
void print_result(const char *group, const char *name, const T& t0, const T& t1)
{
std::cout
<< std::left << std::setw(10) << group << std::right
<< std::setw(15) << name
<< std::setw(20) << t0
<< std::setw(20) << t1
<< std::setw(20) << seconds(t1-t0)
<< std::endl;
}
}
int main(int argc, char *argv[])
{
const auto std_system_time_0 = std::chrono::system_clock::now();
const auto std_steady_time_0 = std::chrono::steady_clock::now();
const auto boost_system_time_0 = boost::chrono::system_clock::now();
const auto boost_steady_time_0 = boost::chrono::steady_clock::now();
std::cout << "Change system clock and press Enter..." << std::endl;
getchar();
const auto std_system_time_1 = std::chrono::system_clock::now();
const auto std_steady_time_1 = std::chrono::steady_clock::now();
const auto boost_system_time_1 = boost::chrono::system_clock::now();
const auto boost_steady_time_1 = boost::chrono::steady_clock::now();
std::cout
<< std::setw(25) << ""
<< std::setw(20) << "t0, ticks"
<< std::setw(20) << "t1, ticks"
<< std::setw(20) << "t1 - t0, s"
<< std::endl;
print_result("std", "system_clock", std_system_time_0, std_system_time_1);
print_result("std", "steady_clock", std_steady_time_0, std_steady_time_1);
print_result("boost", "system_clock", boost_system_time_0, boost_system_time_1);
print_result("boost", "steady_clock", boost_steady_time_0, boost_steady_time_1);
return 0;
}