2 * Code taken from the Haskell "clock" package.
4 * Copyright (c) 2009-2012, Cetin Sert
5 * Copyright (c) 2010, Eugene Kirpichov
11#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
12 #define U64(x) x##Ui64
17#define DELTA_EPOCH_IN_100NS U64(116444736000000000)
19static long ticks_to_nanos(LONGLONG subsecond_time, LONGLONG frequency)
21 return (long)((1e9 * subsecond_time) / frequency);
24static ULONGLONG to_quad_100ns(FILETIME ft)
27 li.LowPart = ft.dwLowDateTime;
28 li.HighPart = ft.dwHighDateTime;
32static void to_timespec_from_100ns(ULONGLONG t_100ns, long long *t)
34 t[0] = (long)(t_100ns / 10000000UL);
35 t[1] = 100*(long)(t_100ns % 10000000UL);
38void clock_gettime_win32_monotonic(long long* t)
41 LARGE_INTEGER frequency;
42 QueryPerformanceCounter(&time);
43 QueryPerformanceFrequency(&frequency);
45 t[0] = time.QuadPart / frequency.QuadPart;
47 t[1] = ticks_to_nanos(time.QuadPart % frequency.QuadPart, frequency.QuadPart);
50void clock_gettime_win32_realtime(long long* t)
55 GetSystemTimeAsFileTime(&ft);
57 tmp = to_quad_100ns(ft);
58 tmp -= DELTA_EPOCH_IN_100NS;
60 to_timespec_from_100ns(tmp, t);
63void clock_gettime_win32_processtime(long long* t)
65 FILETIME creation_time, exit_time, kernel_time, user_time;
68 GetProcessTimes(GetCurrentProcess(), &creation_time, &exit_time, &kernel_time, &user_time);
69 // Both kernel and user, acc. to http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_117
71 time = to_quad_100ns(user_time) + to_quad_100ns(kernel_time);
72 to_timespec_from_100ns(time, t);
75void clock_gettime_win32_threadtime(long long* t)
77 FILETIME creation_time, exit_time, kernel_time, user_time;
80 GetThreadTimes(GetCurrentThread(), &creation_time, &exit_time, &kernel_time, &user_time);
81 // Both kernel and user, acc. to http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap03.html#tag_03_117
83 time = to_quad_100ns(user_time) + to_quad_100ns(kernel_time);
84 to_timespec_from_100ns(time, t);
87void clock_getres_win32_monotonic(long long* t)
89 LARGE_INTEGER frequency;
90 QueryPerformanceFrequency(&frequency);
92 ULONGLONG resolution = U64(1000000000)/frequency.QuadPart;
93 t[0] = resolution / U64(1000000000);
94 t[1] = resolution % U64(1000000000);
97void clock_getres_win32_realtime(long long* t)
103void clock_getres_win32_processtime(long long* t)
109void clock_getres_win32_threadtime(long long* t)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list