-
Notifications
You must be signed in to change notification settings - Fork 0
/
dl_time.cpp
104 lines (86 loc) · 3.23 KB
/
dl_time.cpp
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
97
98
99
100
101
102
103
104
/*===========================================================================
*
* File: Dl_time.CPP
* Author: Dave Humphrey (uesp@m0use.net)
* Created On: Wednesday, June 20, 2001
*
* Contains common time related routines.
*
*=========================================================================*/
/* Include Files */
#include "dl_time.h"
/*===========================================================================
*
* Begin Local Variable Definitions
*
*=========================================================================*/
DEFINE_FILE("dl_time.h");
/*===========================================================================
* End of Local Variable Definitions
*=========================================================================*/
/*===========================================================================
*
* Function - void GetHiClock (Counter);
*
* Gets the current value of the system's high-resolution counter, if any.
* The counter used depends on the system. By default the standard clock()
* routine is used.
*
*=========================================================================*/
void GetHiClock (hiclock_t& Counter) {
/* Attempt to use the performance counter */
#if defined(_WIN32)
boolean Result;
/* Attempt to get the performance timer count */
Result = QueryPerformanceCounter(&Counter.TimerCount);
/* Set the counter type and return on success */
if (Result) {
Counter.CountType = HICLOCK_PERFORMANCE;
return;
}
#endif
/* Use the clock() count by default */
Counter.ClockCount = clock();
Counter.CountType = HICLOCK_CLOCK;
}
/*===========================================================================
* End of Function GetHiClock()
*=========================================================================*/
/*===========================================================================
*
* Function - double GetHiClockTime (void);
*
* Returns the time of the system clock in seconds.
*
*=========================================================================*/
double GetHiClockTime (void) {
hiclock_t CurrentClock;
GetHiClock(CurrentClock);
return ( ((double)CurrentClock) / GetHiClockFreq() );
}
/*===========================================================================
* End of Function GetHiClockTime()
*=========================================================================*/
/*===========================================================================
*
* Function - double GetHiClockFreq (void);
*
* Returns the frequency of the system's high-resolution counter in Hz.
*
*=========================================================================*/
double GetHiClockFreq (void) {
/* Attempt to use the performance counter */
#if defined(_WIN32)
LARGE_INTEGER Freq;
int Result;
Result = QueryPerformanceFrequency(&Freq);
if (!Result || Freq.QuadPart == 0) return (double)(1.0);
return ((double)Freq.QuadPart);
/* Use the clock() frequency */
#else
return ((double) CLOCKS_PER_SEC);
#endif
}
/*===========================================================================
* End of Function GetHiClockFreq()
*=========================================================================*/