-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtimer.cpp
More file actions
98 lines (75 loc) · 1.61 KB
/
Copy pathtimer.cpp
File metadata and controls
98 lines (75 loc) · 1.61 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
/*
* timer.cpp
* Author: David Wu
*/
#ifdef _WIN32
#define _TIMER_IS_WINDOWS
#elif _WIN64
#define _TIMER_IS_WINDOWS
#elif __unix || __APPLE__
#define _TIMER_IS_UNIX
#else
#error Unknown OS!
#endif
#ifdef _TIMER_IS_WINDOWS
#include <windows.h>
#endif
#ifdef _TIMER_IS_UNIX
#include <sys/time.h>
#endif
#include <stdint.h>
#include <ctime>
#include "timer.h"
using namespace std;
//WINDOWS IMPLMENTATIION-------------------------------------------------------------
#ifdef _TIMER_IS_WINDOWS
ClockTimer::ClockTimer()
{
reset();
}
ClockTimer::~ClockTimer()
{
}
void ClockTimer::reset()
{
initialTime = (int64_t)GetTickCount();
}
double ClockTimer::getSeconds() const
{
int64_t newTime = (int64_t)GetTickCount();
return (double)(newTime-initialTime)/1000.0;
}
int64_t ClockTimer::getPrecisionSystemTime()
{
return (int64_t)GetTickCount();
}
#endif
//UNIX IMPLEMENTATION------------------------------------------------------------------
#ifdef _TIMER_IS_UNIX
ClockTimer::ClockTimer()
{
reset();
}
ClockTimer::~ClockTimer()
{
}
void ClockTimer::reset()
{
struct timeval timeval;
gettimeofday(&timeval,NULL);
initialTime = (int64_t)timeval.tv_sec * 1000000LL + (int64_t)timeval.tv_usec;
}
double ClockTimer::getSeconds() const
{
struct timeval timeval;
gettimeofday(&timeval,NULL);
int64_t newTime = (int64_t)timeval.tv_sec * 1000000LL + (int64_t)timeval.tv_usec;
return (double)(newTime-initialTime)/1000000.0;
}
int64_t ClockTimer::getPrecisionSystemTime()
{
struct timeval timeval;
gettimeofday(&timeval,NULL);
return (int64_t)timeval.tv_sec * 1000000LL + (int64_t)timeval.tv_usec;
}
#endif