Created
July 10, 2014 16:11
-
-
Save PathogenDavid/13450d9fbc79781656bd to your computer and use it in GitHub Desktop.
WaitableTimerTest1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <stdio.h> | |
#include <assert.h> | |
#define NANOSECONDS_PER_SECOND ( 1000000000LL ) | |
#define NANOSECONDS_PER_TIMER ( 100LL ) | |
int main() | |
{ | |
LARGE_INTEGER begin; | |
LARGE_INTEGER end; | |
LARGE_INTEGER timeToWait; | |
HANDLE timer = CreateWaitableTimer(NULL, TRUE, NULL); | |
assert(timer != NULL); | |
timeToWait.QuadPart = -10000LL; //10000 * 100 nanoseconds = 1 ms | |
assert(QueryPerformanceCounter(&begin)); | |
assert(SetWaitableTimer(timer, &timeToWait, 0, NULL, NULL, TRUE)); | |
assert(WaitForSingleObject(timer, INFINITE) == WAIT_OBJECT_0); | |
assert(QueryPerformanceCounter(&end)); | |
LARGE_INTEGER performanceCounterFrequency;//On my machine: 3312841, or 301.9 ns | |
assert(QueryPerformanceFrequency(&performanceCounterFrequency)); | |
LONGLONG delta = end.QuadPart - begin.QuadPart; | |
printf("begin: %I64d\n", begin.QuadPart); | |
printf("end: %I64d\n", end.QuadPart); | |
printf("delta: %I64d ticks\n", delta); | |
printf("delta: %I64d ns\n", (delta * NANOSECONDS_PER_SECOND) / performanceCounterFrequency.QuadPart); | |
printf("timeToWait: %I64d ns\n", -timeToWait.QuadPart * NANOSECONDS_PER_TIMER); | |
printf("frequency : %I64d ticks/second\n", performanceCounterFrequency.QuadPart); | |
printf("Press any key to exit..."); | |
getchar(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment