Created
November 12, 2014 04:42
-
-
Save qi7chen/101b9045f19a7cd15362 to your computer and use it in GitHub Desktop.
get tick counter
This file contains hidden or 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 <stdint.h> | |
| #include <assert.h> | |
| #include <time.h> | |
| #define CHECK assert | |
| #if defined(_MSC_VER) | |
| #include <windows.h> | |
| inline uint64_t getPerformanceFreqency() | |
| { | |
| static LARGE_INTEGER freq; | |
| if (freq.QuadPart == 0) | |
| { | |
| CHECK(QueryPerformanceFrequency(&freq)); | |
| } | |
| return freq.QuadPart; | |
| } | |
| uint64_t getNowTickCount() | |
| { | |
| LARGE_INTEGER now; | |
| CHECK(QueryPerformanceCounter(&now)); | |
| return (now.QuadPart * 1000000000UL) / getPerformanceFreqency(); | |
| } | |
| #elif defined(__GNUC__) | |
| uint64_t getNowTickCount() | |
| { | |
| timespec ts; | |
| CHECK(clock_gettime(CLOCK_REALTIME, &ts) == 0); | |
| return (ts.tv_sec * 1000000000UL) + ts.tv_nsec; | |
| } | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment