int clock_gettime(TimeStampType &time) { LARGE_INTEGER t; FILETIME f; double microseconds; static LARGE_INTEGER offset; static double frequencyToMicroseconds; static int initialized = 0; if (!initialized) { LARGE_INTEGER performanceFrequency; initialized = 1; offset = getFILETIMEoffset(); frequencyToMicroseconds = 10.; } GetSystemTimeAsFileTime(&f); t.QuadPart = f.dwHighDateTime; t.QuadPart <<= 32; t.QuadPart |= f.dwLowDateTime; t.QuadPart -= offset.QuadPart; time = (TimeStampType)t.QuadPart / frequencyToMicroseconds; return 0; }
// ---------------------------------------------------------------------------- // clock_gettime // Returns the time of the specified clock clk_id in nanoseconds precision. // (clock_gettime is missing from Microsoft C) // ---------------------------------------------------------------------------- int clock_gettime(int clk_id, struct timespec *tv) { LARGE_INTEGER t; FILETIME f; //double microseconds; double nanoseconds; static LARGE_INTEGER offset; //static double frequencyToMicroseconds; static double frequencyToNanoseconds; static int initialized = 0; static int usePerformanceCounter = 0; if (!initialized) { LARGE_INTEGER performanceFrequency; initialized = 1; usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency); if (usePerformanceCounter) { QueryPerformanceCounter(&offset); // frequencyToMicroseconds = (double)performanceFrequency.QuadPart / MICROSEC; frequencyToNanoseconds = (double)performanceFrequency.QuadPart / NANOSEC; } else { offset = getFILETIMEoffset(); // frequencyToMicroseconds = 10.0; frequencyToNanoseconds = 0.01; } } if (usePerformanceCounter) QueryPerformanceCounter(&t); else { GetSystemTimeAsFileTime(&f); t.QuadPart = f.dwHighDateTime; t.QuadPart <<= 32; t.QuadPart |= f.dwLowDateTime; } t.QuadPart -= offset.QuadPart; //microseconds = (double)t.QuadPart / frequencyToMicroseconds; nanoseconds = (double)t.QuadPart / frequencyToNanoseconds; //t.QuadPart = (LONGLONG)microseconds; t.QuadPart = (LONGLONG)nanoseconds; //tv->tv_sec = t.QuadPart / MICROSEC; tv->tv_sec = t.QuadPart / NANOSEC; //tv->tv_usec = t.QuadPart % MICROSEC; tv->tv_nsec = t.QuadPart % NANOSEC; return 0; } /* clock_gettime */
int clock_gettime(int X, timespec *tv) { LARGE_INTEGER t; FILETIME f; double microseconds; static LARGE_INTEGER offset; static double frequencyToMicroseconds; static int initialized = 0; static BOOL usePerformanceCounter = 0; if (!initialized) { LARGE_INTEGER performanceFrequency; initialized = 1; usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency); if (usePerformanceCounter) { QueryPerformanceCounter(&offset); frequencyToMicroseconds = (double)performanceFrequency.QuadPart / 1000000.; } else { offset = getFILETIMEoffset(); frequencyToMicroseconds = 10.; } } if (usePerformanceCounter) QueryPerformanceCounter(&t); else { GetSystemTimeAsFileTime(&f); t.QuadPart = f.dwHighDateTime; t.QuadPart <<= 32; t.QuadPart |= f.dwLowDateTime; } t.QuadPart -= offset.QuadPart; microseconds = (double)t.QuadPart / frequencyToMicroseconds; t.QuadPart = microseconds; tv->tv_sec = t.QuadPart / 1000000; tv->tv_usec = t.QuadPart % 1000000; return (0); }
int clock_gettime(clockid_t clk_id, struct timespeca *tp) { LARGE_INTEGER t; FILETIME f; static LARGE_INTEGER offset; static double frequencyToMicroseconds; static int initialized = 0; static BOOL usePerformanceCounter = 0; if (!initialized) { LARGE_INTEGER performanceFrequency; initialized = 1; if (clk_id == CLOCK_MONOTONIC) { usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency); } if (usePerformanceCounter) { QueryPerformanceCounter(&offset); frequencyToMicroseconds = (double)performanceFrequency.QuadPart / 1000000.; } else { offset = getFILETIMEoffset(); frequencyToMicroseconds = 10.; } } if (usePerformanceCounter) QueryPerformanceCounter(&t); else { GetSystemTimeAsFileTime(&f); t.QuadPart = f.dwHighDateTime; t.QuadPart <<= 32; t.QuadPart |= f.dwLowDateTime; } t.QuadPart -= offset.QuadPart; t.QuadPart /= (LONGLONG)frequencyToMicroseconds; tp->tv_sec = t.QuadPart / 1000000ULL; tp->tv_nsec = (t.QuadPart % 1000000ULL) * 1000; return (0); }