-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.cpp
More file actions
132 lines (94 loc) · 3.69 KB
/
timer.cpp
File metadata and controls
132 lines (94 loc) · 3.69 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include<chrono>
#include<cmath>
#include<functional>
//This file introduces the timer_x_args function.
//It accepts a function with no arguments as a parameter.
//to add arguments, simply insert them into timeAFunction, and
//then into t();
//For Example:
//std::chrono::duration<double> timeAFunction(int a, double b,T t){
//t(a, b);
//on the appropriate lines
//since it returns a duration<double> the easiest way to stream this is to use
//the .count() method.
//For Example (in a different source file):
//auto funcTime = timer_no_args(function);
//std::cout << funcTime.count() << std::endl;
template<typename T>
std::chrono::duration<double> timer(T t){
//get starting time
std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
//execute function
t();
//get end time
std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
//total = end minus start
std::chrono::duration<double> totalTime = end - start;
//return total
return totalTime;
}
template<typename T, typename arg1>
std::chrono::duration<double> timer(arg1 a1,T t){
//get starting time
std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
//execute function
t(a1);
//get end time
std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
//total = end minus start
std::chrono::duration<double> totalTime = end - start;
//return total
return totalTime;
}
template<typename T, typename arg1,typename arg2>
std::chrono::duration<double> timer(arg1 a1, arg2 a2, T t){
//get starting time
std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
//execute function
t(a1,a2);
//get end time
std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
//total = end minus start
std::chrono::duration<double> totalTime = end - start;
//return total
return totalTime;
}
template<typename T, typename arg1,typename arg2,typename arg3>
std::chrono::duration<double> timer(arg1 a1, arg2 a2, arg3 a3, T t){
//get starting time
std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
//execute function
t(a1,a2,a3);
//get end time
std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
//total = end minus start
std::chrono::duration<double> totalTime = end - start;
//return total
return totalTime;
}
template<typename T, typename arg1,typename arg2,typename arg3, typename arg4>
std::chrono::duration<double> timer(arg1 a1, arg2 a2, arg3 a3,arg4 a4, T t){
//get starting time
std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
//execute function
t(a1,a2,a3,a4);
//get end time
std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
//total = end minus start
std::chrono::duration<double> totalTime = end - start;
//return total
return totalTime;
}
template<typename T, typename arg1,typename arg2,typename arg3,typename arg4,typename arg5>
std::chrono::duration<double> timer(arg1 a1, arg2 a2, arg3 a3,arg4 a4,arg5 a5, T t){
//get starting time
std::chrono::time_point<std::chrono::high_resolution_clock> start = std::chrono::high_resolution_clock::now();
//execute function
t(a1,a2,a3,a4,a5);
//get end time
std::chrono::time_point<std::chrono::high_resolution_clock> end = std::chrono::high_resolution_clock::now();
//total = end minus start
std::chrono::duration<double> totalTime = end - start;
//return total
return totalTime;
}