-
Notifications
You must be signed in to change notification settings - Fork 0
/
hr_time.c
43 lines (32 loc) · 1.49 KB
/
hr_time.c
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
#include <windows.h>
#include "hr_time.h"
// CTRL + SHIFT + G to create auto documentation
// ----------------------------------------------------------------------------
static double LIToSecs(LARGE_INTEGER * L);
// ----------------------------------------------------------------------------
/// HIFN Starts the timer passed as paramter
/// HIPAR timer/Pointer to the timer to be started
void StartTimer(HRWatch *timer) {
QueryPerformanceCounter(&timer->start);
}
// ----------------------------------------------------------------------------
/// HIFN Starts the timer passed as paramter
/// HIPAR timer/Pointer to the timer to be stopped
void StopTimer(HRWatch *timer) {
QueryPerformanceCounter(&timer->stop);
}
// ----------------------------------------------------------------------------
static double LIToSecs(LARGE_INTEGER *L) {
LARGE_INTEGER frequency;
QueryPerformanceFrequency( &frequency );
return ((double)L->QuadPart /(double)frequency.QuadPart);
}
// ----------------------------------------------------------------------------
/// HIFN For the timer passed as parameter returns the elapsed time between the StartTimer() and StopTimer() function calls.
/// HIRET The elapsed time between the StartTimer() and StopTimer() function calls
/// HIPAR timer/double - The timer for wich you wants to get the elapsed time
double GetElapsedTime(HRWatch *timer) {
LARGE_INTEGER time;
time.QuadPart = timer->stop.QuadPart - timer->start.QuadPart;
return LIToSecs(&time) ;
}