|
|
@ -1,4 +1,7 @@
|
|
|
|
|
|
|
|
// Returns the amount of milliseconds elapsed since the UNIX epoch.
|
|
|
|
|
|
|
|
// Works on both windows and linux.
|
|
|
|
// source: http://stackoverflow.com/questions/1861294/how-to-calculate-execution-time-of-a-code-snippet-in-c
|
|
|
|
// source: http://stackoverflow.com/questions/1861294/how-to-calculate-execution-time-of-a-code-snippet-in-c
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <Windows.h>
|
|
|
|
#else
|
|
|
|
#else
|
|
|
@ -6,40 +9,39 @@
|
|
|
|
#include <ctime>
|
|
|
|
#include <ctime>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* Returns the amount of milliseconds elapsed since the UNIX epoch. Works on both
|
|
|
|
#ifdef LINUX_BUILD // Linux
|
|
|
|
* windows and linux. */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t GetTimeMs64()
|
|
|
|
uint64_t GetTimeMs64()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
struct timeval tv;
|
|
|
|
/* Windows */
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
FILETIME ft;
|
|
|
|
uint64_t ret = tv.tv_usec;
|
|
|
|
LARGE_INTEGER li;
|
|
|
|
|
|
|
|
|
|
|
|
// Convert from micro seconds (10^-6) to milliseconds (10^-3)
|
|
|
|
/* Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC) and copy it
|
|
|
|
ret /= 1000;
|
|
|
|
* to a LARGE_INTEGER structure. */
|
|
|
|
// Adds the seconds (10^0) after converting them to milliseconds (10^-3)
|
|
|
|
GetSystemTimeAsFileTime(&ft);
|
|
|
|
ret += (tv.tv_sec * 1000);
|
|
|
|
li.LowPart = ft.dwLowDateTime;
|
|
|
|
return ret;
|
|
|
|
li.HighPart = ft.dwHighDateTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t ret = li.QuadPart;
|
|
|
|
|
|
|
|
ret -= 116444736000000000LL; /* Convert from file time to UNIX epoch time. */
|
|
|
|
|
|
|
|
ret /= 10000; /* From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* Linux */
|
|
|
|
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t ret = tv.tv_usec;
|
|
|
|
|
|
|
|
/* Convert from micro seconds (10^-6) to milliseconds (10^-3) */
|
|
|
|
|
|
|
|
ret /= 1000;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Adds the seconds (10^0) after converting them to milliseconds (10^-3) */
|
|
|
|
|
|
|
|
ret += (tv.tv_sec * 1000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
#else // Windows
|
|
|
|
#endif
|
|
|
|
uint64_t GetTimeMs64()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
FILETIME ft;
|
|
|
|
|
|
|
|
LARGE_INTEGER li;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get the amount of 100 nano seconds intervals elapsed since January 1, 1601 (UTC)
|
|
|
|
|
|
|
|
// and copy it to a LARGE_INTEGER structure.
|
|
|
|
|
|
|
|
GetSystemTimeAsFileTime(&ft);
|
|
|
|
|
|
|
|
li.LowPart = ft.dwLowDateTime;
|
|
|
|
|
|
|
|
li.HighPart = ft.dwHighDateTime;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t ret = li.QuadPart;
|
|
|
|
|
|
|
|
// Convert from file time to UNIX epoch time.
|
|
|
|
|
|
|
|
ret -= 116444736000000000LL;
|
|
|
|
|
|
|
|
// From 100 nano seconds (10^-7) to 1 millisecond (10^-3) intervals
|
|
|
|
|
|
|
|
ret /= 10000;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|