-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.cpp
84 lines (72 loc) · 1.64 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
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
82
83
84
#include <iostream>
#include <chrono> // for high_resolution_clock
template <typename Function>
void MeasureExecutionTimes(Function&& aPortionOfCode)
{
// Record start time
auto start = std::chrono::high_resolution_clock::now();
// Portion of code to be timed
aPortionOfCode();
// Record end time
auto finish = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = finish - start;
std::cout << "Elapsed time: " << std::fixed << elapsed.count() << " s\n";
}
// MacBook Pro (15-inch, 2018)
// Процессор 2,2 GHz 6‑ядерный процессор Intel Core i7
// Память 16 ГБ 2400 MHz DDR4
void test1()
{
MeasureExecutionTimes([](){});
}
// Elapsed time: 0.000000 s
// Ten thousand
void test2()
{
MeasureExecutionTimes([]() {
for (int i = 0; i < 10000; ++i) {}
});
}
// Elapsed time: 0.000014 s
// Elapsed time: 0.000021 s
// Million
void test3()
{
MeasureExecutionTimes([]() {
for (int i = 0; i < 1000000; ++i) {}
});
}
// Elapsed time: 0.001796 s
// Elapsed time: 0.001898 s
// Ten millions
void test4()
{
MeasureExecutionTimes([]() {
for (int i = 0; i < 10000000; ++i) {}
});
}
// Elapsed time: 0.018046 s
// Elapsed time: 0.018795 s
// Hundred million
void test5()
{
MeasureExecutionTimes([]() {
for (int i = 0; i < 100000000; ++i) {}
});
}
// Elapsed time: 0.140169 s
// Elapsed time: 0.188318 s
// Billion
void test6()
{
MeasureExecutionTimes([]() {
for (int i = 0; i < 1000000000; ++i) {}
});
}
// Elapsed time: 1.428908 s
// Elapsed time: 1.472331 s
int main()
{
test6();
return 0;
}