16 struct timespec start;
17 clock_gettime(CLOCK_REALTIME, &start);
19 *nsec = start.tv_nsec;
21 struct timeval timeofday;
22 gettimeofday(&timeofday,NULL);
23 sec = timeofday.tv_sec;
24 nsec = timeofday.tv_usec * 1000;
37 static LARGE_INTEGER cpu_freq, init_cpu_time;
38 static uint32_t start_sec = 0;
39 static uint32_t start_nsec = 0;
40 if ( ( start_sec == 0 ) && ( start_nsec == 0 ) )
42 QueryPerformanceFrequency(&cpu_freq);
43 if (cpu_freq.QuadPart == 0) {
44 throw NoHighPerformanceTimersException();
46 QueryPerformanceCounter(&init_cpu_time);
49 GetSystemTimeAsFileTime(&ft);
50 LARGE_INTEGER start_li;
51 start_li.LowPart = ft.dwLowDateTime;
52 start_li.HighPart = ft.dwHighDateTime;
56 start_li.QuadPart -= 116444736000000000Ui64;
58 start_li.QuadPart -= 116444736000000000ULL;
60 start_sec = (uint32_t)(start_li.QuadPart / 10000000);
61 start_nsec = (start_li.LowPart % 10000000) * 100;
63 LARGE_INTEGER cur_time;
64 QueryPerformanceCounter(&cur_time);
65 LARGE_INTEGER delta_cpu_time;
66 delta_cpu_time.QuadPart = cur_time.QuadPart - init_cpu_time.QuadPart;
69 double d_delta_cpu_time = delta_cpu_time.QuadPart / (double) cpu_freq.QuadPart;
70 uint32_t delta_sec = (uint32_t) floor(d_delta_cpu_time);
71 uint32_t delta_nsec = (uint32_t) boost::math::round((d_delta_cpu_time-delta_sec) * 1e9);
73 int64_t sec_sum = (int64_t)start_sec + (int64_t)delta_sec;
74 int64_t nsec_sum = (int64_t)start_nsec + (int64_t)delta_nsec;
77 normalizeSecNSecUnsigned(sec_sum, nsec_sum);
88 *nsecs = (
unsigned long long)sec*1000000000ll + (
unsigned long long)nsec;