Returns current value of performance counter
| 1034 | |
| 1035 | // Returns current value of performance counter |
| 1036 | SINT64 query_performance_counter() |
| 1037 | { |
| 1038 | #if defined(WIN_NT) |
| 1039 | |
| 1040 | // Use Windows performance counters |
| 1041 | LARGE_INTEGER counter; |
| 1042 | if (QueryPerformanceCounter(&counter) == 0) |
| 1043 | return 0; |
| 1044 | |
| 1045 | return counter.QuadPart; |
| 1046 | #elif defined(HAVE_CLOCK_GETTIME) |
| 1047 | |
| 1048 | // Use high-resolution clock |
| 1049 | struct timespec tp; |
| 1050 | if (clock_gettime(CLOCK_MONOTONIC_RAW, &tp) != 0) |
| 1051 | return 0; |
| 1052 | |
| 1053 | return static_cast<SINT64>(tp.tv_sec) * BILLION + tp.tv_nsec; |
| 1054 | #else |
| 1055 | |
| 1056 | // This is not safe because of possible wrapping and very imprecise |
| 1057 | return clock(); |
| 1058 | #endif |
| 1059 | } |
| 1060 | |
| 1061 | |
| 1062 | // Returns frequency of performance counter in Hz |
no test coverage detected