-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlatformIndependentTimer.h
67 lines (58 loc) · 1.85 KB
/
PlatformIndependentTimer.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
/*=============================================================================
Title : PlatformIndependentTimer.h
Description : Implementation of a very accurate platform independent timer
Notes : None
History :
Copyright (c) 2012 Bitwise Systems. All rights reserved.
This software contains confidential information and trade secrets of
Bitwise Systems and is protected by United States and international
copyright laws. Use, disclosure, or reproduction is prohibited without
the prior express written permission of Bitwise Systems, except as agreed
in the QuickUSB Plug-In Module license agreement.
Use, duplication or disclosure by the U.S. Government is subject to
restrictions as provided in DFARS 227.7202-1(a) and 227.7202-3(a)
(1998), and FAR 12.212, as applicable. Bitwise Systems, 6489 Calle Real,
Suite E, Goleta, CA 93117.
Bitwise Systems
6489 Calle Real, Suite E
Santa Barbara, CA 93117
Voice: (805) 683-6469
Fax : (805) 683-4833
Web : www.bitwisesys.com
email: [email protected]
=============================================================================*/
#include <ctime>
#if defined(__APPLE__)
#include <sys/time.h>
#endif
#if defined(__linux__) || defined(__APPLE__)
#include <sys/syscall.h>
#endif
#if defined(__linux__)
#define SleepMS(x) usleep((x) * 1000)
#endif
#if defined(__APPLE__)
#define SleepMS(x) usleep((x) * 1000)
#endif
#if defined(_WIN32)
#include <windows.h>
#define SleepMS(x) Sleep(x)
#endif
class PlatformIndependentTimer {
public:
PlatformIndependentTimer();
void Start();
void Stop();
double GetElapsedTimeInSeconds();
private:
bool running;
#if defined(__linux__)
timespec tStart, tEnd;
#endif
#if defined(__APPLE__)
timeval tStart, tEnd;
#endif
#if defined(_WIN32)
LARGE_INTEGER freq, tStart, tEnd;
#endif
};