diff options
| author | Stefan Boberg <[email protected]> | 2021-05-11 13:05:39 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-05-11 13:05:39 +0200 |
| commit | f8d9ac5d13dd37b8b57af0478e77ba1e75c813aa (patch) | |
| tree | 1daf7621e110d48acd5e12e3073ce48ef0dd11b2 /zencore/timer.cpp | |
| download | zen-f8d9ac5d13dd37b8b57af0478e77ba1e75c813aa.tar.xz zen-f8d9ac5d13dd37b8b57af0478e77ba1e75c813aa.zip | |
Adding zenservice code
Diffstat (limited to 'zencore/timer.cpp')
| -rw-r--r-- | zencore/timer.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/zencore/timer.cpp b/zencore/timer.cpp new file mode 100644 index 000000000..ee8e1cf9c --- /dev/null +++ b/zencore/timer.cpp @@ -0,0 +1,67 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include <doctest/doctest.h> +#include <zencore/thread.h> +#include <zencore/timer.h> +#include <zencore/windows.h> + +namespace zen { + +uint64_t +GetHifreqTimerValue() +{ + LARGE_INTEGER li; + QueryPerformanceCounter(&li); + + return li.QuadPart; +} + +uint64_t +internalGetHifreqTimerFrequency() +{ + LARGE_INTEGER li; + QueryPerformanceFrequency(&li); + + return li.QuadPart; +} + +static uint64_t qpcFreq = internalGetHifreqTimerFrequency(); + +uint64_t +GetHifreqTimerFrequency() +{ + return qpcFreq; +} + +uint64_t +GetHifreqTimerFrequencySafe() +{ + if (!qpcFreq) + qpcFreq = internalGetHifreqTimerFrequency(); + + return qpcFreq; +} + +////////////////////////////////////////////////////////////////////////// +// +// Testing related code follows... +// + +void +timer_forcelink() +{ +} + +TEST_CASE("Timer") +{ + uint64_t s0 = GetHifreqTimerValue(); + uint64_t t0 = GetCpuTimerValue(); + Sleep(1000); + uint64_t s1 = GetHifreqTimerValue(); + uint64_t t1 = GetCpuTimerValue(); + // double r = double(t1 - t0) / (s1 - s0); + CHECK_NE(t0, t1); + CHECK_NE(s0, s1); +} + +} // namespace zen |