From f8d9ac5d13dd37b8b57af0478e77ba1e75c813aa Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Tue, 11 May 2021 13:05:39 +0200 Subject: Adding zenservice code --- zencore/timer.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 zencore/timer.cpp (limited to 'zencore/timer.cpp') 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 +#include +#include +#include + +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 -- cgit v1.2.3