This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
forked from huiprobable/CellsMD3D
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathClockIt.h
79 lines (63 loc) · 1.65 KB
/
ClockIt.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
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
#ifndef _ClockIt_
#define _ClockIt_
#include <sys/time.h>
//
// Class ClockIt can be used on a Linux/Unix system to time portions of code. It
// depends upon calls to the gettimeofday(..) function in sys/time.h to read the system
// clock.
//
// Usage snippet:
//
/*
int main()
{
ClockIt clock1; // declare ClockIt instance
clock1.start(); // start the instance (reads the clock)
// === Code to be timed === // // carry out computation
clock1.stop(); // stop the clock (reads the clock again)
cout << "Time elapsed in Milli-seconds" << clock1.getMilliSecElapsedTime() << endl;
}
*/
class ClockIt
{
public:
ClockIt()
{
elapsedTime = 0;
}
ClockIt(const ClockIt& clock)
{
elapsedTime = clock.elapsedTime;
t1 = clock.t1;
t2 = clock.t2;
}
//
// Reads the clock
//
inline void start() {gettimeofday(&t1, 0);}
//
// Reads the clock again, and computes the
// the elapsed time.
//
// Returns the time in milliseconds since start() called
//
inline double stop()
{
gettimeofday(&t2, 0);
//
// Compute elapsed time in milliseconds
//
elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; // seconds to milliseconds
elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // microseconds to milliseconds
return elapsedTime;
}
double getMilliSecElapsedTime()
{return elapsedTime;}
double getMicroSecElapsedTime()
{return elapsedTime*1000.0;}
double getSecElapsedTime()
{return elapsedTime/1000.0;}
timeval t1, t2;
double elapsedTime;
};
#endif