-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.h
49 lines (37 loc) · 1020 Bytes
/
timer.h
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
#ifndef TIMER
#define TIMER
#include <ctime>
/*
Simple class to calculate program timings.
Usage
-----
* call the constructor at the start of the function you want to time
* to get the current runtime between timing()-calls call timing()
* The total runtime can be accessed by calling total_timing()
*/
//creates object that can keep track of time in program
class timer
{
private:
clock_t start_stamp, last_stamp, current_stamp;
public:
timer()
{
start_stamp = clock();
last_stamp = start_stamp;
}
float timing()
{
current_stamp = clock();
float t_diff ((float)current_stamp - (float)last_stamp);
last_stamp = current_stamp;
return t_diff/CLOCKS_PER_SEC;
}
float total_timing()
{
current_stamp = clock();
float t_diff ((float)current_stamp - (float)start_stamp);
return t_diff/CLOCKS_PER_SEC;
}
};
#endif