-
Notifications
You must be signed in to change notification settings - Fork 1
/
Timer.h
64 lines (55 loc) · 2.25 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//////////////////////////////////////////////////////////////////////////////
// Timer.h
// =======
// High Resolution Timer.
// This timer is able to measure the elapsed time with 1 micro-second accuracy
// in both Windows, Linux and Unix system
//
// AUTHOR: Song Ho Ahn ([email protected])
// CREATED: 2003-01-13
// UPDATED: 2006-01-13
//
// Copyright (c) 2003 Song Ho Ahn
//////////////////////////////////////////////////////////////////////////////
#ifndef TIMER_H_DEF
#define TIMER_H_DEF
#ifdef WIN32 // Windows system specific
#include <windows.h>
#else // Unix based system specific
#include <sys/time.h>
#endif
class Timer
{
public:
Timer(); // default constructor
~Timer(); // default destructor
void start(); // start timer
void stop(); // stop the timer
double getElapsedTimeInMicroSec(); // get elapsed time in micro-second
double getElapsedTimeInMilliSec(); // get elapsed time in milli-second
double getElapsedTimeInSec(); // get elapsed time in second (same as getElapsedTime)
#ifdef WIN32
long getCurrentTimeInMilliSec();
LARGE_INTEGER getCurrentTime();
double getElapsedTimeInMicroSec( LARGE_INTEGER startTime, LARGE_INTEGER endTime );
double getElapsedTimeInMilliSec( LARGE_INTEGER startTime, LARGE_INTEGER endTime );
#else
timeval getCurrentTime();
double getElapsedTimeInMicroSec( timeval startTime, timeval endTime );
double getElapsedTimeInMilliSec( timeval startTime, timeval endTime );
#endif
protected:
private:
double startTimeInMicroSec; // starting time in micro-second
double endTimeInMicroSec; // ending time in micro-second
int stopped; // stop flag
#ifdef WIN32
LARGE_INTEGER frequency; // ticks per second
LARGE_INTEGER startCount; //
LARGE_INTEGER endCount; //
#else
timeval startCount; //
timeval endCount; //
#endif
};
#endif // TIMER_H_DEF