mirror of
https://github.com/isar/libmdbx.git
synced 2025-12-17 17:32:24 +08:00
test: add rnd and delay tools.
This commit is contained in:
@@ -71,7 +71,7 @@ time from_ms(uint64_t ms) {
|
||||
return result;
|
||||
}
|
||||
|
||||
time now() {
|
||||
time now_realtime() {
|
||||
#if defined(_WIN32) || defined(_WIN64) || defined(_WINDOWS)
|
||||
FILETIME filetime;
|
||||
GetSystemTimeAsFileTime(&filetime);
|
||||
@@ -87,4 +87,35 @@ time now() {
|
||||
#endif
|
||||
}
|
||||
|
||||
time now_motonic() {
|
||||
#if defined(_WIN32) || defined(_WIN64) || defined(_WINDOWS)
|
||||
static uint32_t reciprocal;
|
||||
static LARGE_INTEGER Frequency;
|
||||
if (reciprocal == 0) {
|
||||
if (!QueryPerformanceFrequency(&Frequency))
|
||||
failure_perror("QueryPerformanceFrequency()", GetLastError());
|
||||
reciprocal = (UINT64_C(1) << 32) / Frequency.QuadPart;
|
||||
assert(reciprocal);
|
||||
}
|
||||
|
||||
LARGE_INTEGER Counter;
|
||||
if (!QueryPerformanceCounter(&Counter))
|
||||
failure_perror("QueryPerformanceCounter()", GetLastError());
|
||||
|
||||
time result;
|
||||
result.integer = Counter.QuadPart / Frequency.QuadPart;
|
||||
uint64_t mod = Counter.QuadPart % Frequency.QuadPart;
|
||||
assert(mod < UINT32_MAX);
|
||||
result.fractional = UInt32x32To64((uint32_t)mod, reciprocal);
|
||||
assert(result.fractional == (mod << 32) / Frequency.QuadPart);
|
||||
return result;
|
||||
#else
|
||||
struct timespec ts;
|
||||
if (unlikely(clock_gettime(CLOCK_MONOTONIC, &ts)))
|
||||
failure_perror("clock_gettime(CLOCK_MONOTONIC)", errno);
|
||||
|
||||
return from_timespec(ts);
|
||||
#endif
|
||||
}
|
||||
|
||||
} /* namespace chrono */
|
||||
|
||||
Reference in New Issue
Block a user