Skip to content

Instantly share code, notes, and snippets.

@qi7chen
Created November 12, 2014 04:42
Show Gist options
  • Select an option

  • Save qi7chen/101b9045f19a7cd15362 to your computer and use it in GitHub Desktop.

Select an option

Save qi7chen/101b9045f19a7cd15362 to your computer and use it in GitHub Desktop.
get tick counter
#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