[-] last trace of the high res clock

This commit is contained in:
Reece Wilson 2023-09-18 22:26:19 +01:00
parent 5ef6e0cd23
commit e60c891eac

View File

@ -9,70 +9,62 @@
#include "AuClock.hpp" #include "AuClock.hpp"
#include "Time.hpp" #include "Time.hpp"
#if defined(AURORA_IS_MODERNNT_DERIVED) #if defined(AURORA_IS_POSIX_DERIVED)
#include <sys/resource.h>
#elif defined(AURORA_IS_MODERNNT_DERIVED)
// TODO (Reece): .... #define timegm _mkgmtime
// benchmarking: // benchmarking: https://github.com/microsoft/STL/issues/2085
// https://github.com/microsoft/STL/issues/2085 static AuUInt64 _GetSteadyTimeNS()
static AuUInt64 _GetSteadyTimeNS()
{
static const long long gFreq = _Query_perf_frequency();
const long long uCounter = _Query_perf_counter();
if (gFreq == 10000000)
{ {
return uCounter * 100; static const long long gFreq = _Query_perf_frequency();
const long long uCounter = _Query_perf_counter();
if (gFreq == 10000000)
{
return uCounter * 100;
}
else if (gFreq == 1000000)
{
return uCounter * 1000;
}
else if (gFreq == 100000)
{
return uCounter * 10000;
}
else if (gFreq == 100000000)
{
return uCounter * 10;
}
else if (gFreq == 1000000000)
{
return uCounter;
}
else
{
// 6 branches: the default threshold for most jit and language compiler backends to decide to pick a jump table, if the values were in a close range
// otherwise, back to a tree of paths. either way, im sure 6 if elses are faster than grug math with large numbers, modulus, division, and multiplication
const long long uWhole = (uCounter / gFreq) * 1'000'000'000ull;
const long long uPart = (uCounter % gFreq) * 1'000'000'000ull / gFreq;
return uWhole + uPart;
}
} }
else if (gFreq == 1000000) // ~3.0741 seconds
{
return uCounter * 1000; // ~6.07 seconds
} // using high_res_clock = std::chrono::high_resolution_clock;
else if (gFreq == 100000)
{ // holy fuck, we're keeping this
return uCounter * 10000; // ~2x improvement
}
else if (gFreq == 100000000)
{
return uCounter * 10;
}
else if (gFreq == 1000000000)
{
return uCounter;
}
else
{
// 6 branches: the default threshold for most jit and language compiler backends to decide to pick a jump table, if the values were in a close range
// otherwise, back to a tree of paths. either way, im sure 6 if elses are faster than grug math with large numbers, modulus, division, and multiplication
const long long uWhole = (uCounter / gFreq) * 1'000'000'000ull;
const long long uPart = (uCounter % gFreq) * 1'000'000'000ull / gFreq;
return uWhole + uPart;
}
}
// ~3.0741 seconds
//using high_res_clock = steady_clock_fast;
// holy fuck, we're keeping this
// ~2x improvement
#else #else
using steady_clock = std::chrono::steady_clock;
// ~6.07 seconds
//using high_res_clock = std::chrono::high_resolution_clock;
#endif #endif
#if defined(AURORA_IS_POSIX_DERIVED) using sys_clock = std::chrono::system_clock; // more stds to remove
#include <sys/resource.h>
#endif
using sys_clock = std::chrono::system_clock;
using steady_clock = std::chrono::steady_clock;
#if defined(AURORA_PLATFORM_WIN32)
#define timegm _mkgmtime
#endif
static sys_clock::duration gEpoch; static sys_clock::duration gEpoch;
static sys_clock::duration gUnixDelta; static sys_clock::duration gUnixDelta;
@ -134,12 +126,6 @@ static AuInt64 _CurrentClockNS()
namespace Aurora::Time namespace Aurora::Time
{ {
// removed from public header / deprecating
AUKN_SYM AuUInt64 HighResClock();
AUKN_SYM AuUInt64 HighResClockNS();
AUKN_SYM AuUInt64 HighResClockMS();
AUKN_SYM AuUInt64 HighResClockJiffies();
AUKN_SYM time_t SToCTime(AuInt64 time) AUKN_SYM time_t SToCTime(AuInt64 time)
{ {
return CalculateTimeT<std::chrono::seconds>(time); return CalculateTimeT<std::chrono::seconds>(time);
@ -340,7 +326,7 @@ namespace Aurora::Time
} \ } \
return (expr) * 100ull; \ return (expr) * 100ull; \
} \ } \
return HighResClockNS(); \ return 0; \
} \ } \
\ \
AUKN_SYM AuUInt64 fn ## Clock() \ AUKN_SYM AuUInt64 fn ## Clock() \
@ -396,7 +382,7 @@ namespace Aurora::Time
{ \ { \
return AuMSToNS<AuUInt64>(AuSToMS<AuUInt64>(spec.tv_sec)) + (AuUInt64)spec.tv_nsec; \ return AuMSToNS<AuUInt64>(AuSToMS<AuUInt64>(spec.tv_sec)) + (AuUInt64)spec.tv_nsec; \
} \ } \
return HighResClockNS(); \ return 0; \
} \ } \
\ \
AUKN_SYM AuUInt64 fn ## Clock() \ AUKN_SYM AuUInt64 fn ## Clock() \
@ -434,7 +420,7 @@ namespace Aurora::Time
} \ } \
} \ } \
\ \
return HighResClockJiffies(); \ return 0; \
} }
#else #else
@ -558,29 +544,4 @@ namespace Aurora::Time
return ToCivilTime(FromCivilTime(time, shift == ETimezoneShift::eUTC)); return ToCivilTime(FromCivilTime(time, shift == ETimezoneShift::eUTC));
} }
#pragma region TO_DEPRECATE
// [soon to be] @deprecated / was used by benchmarks to measure thread time
AUKN_SYM AuUInt64 HighResClock()
{
return SteadyClock();
}
AUKN_SYM AuUInt64 HighResClockMS()
{
return SteadyClockMS();
}
AUKN_SYM AuUInt64 HighResClockNS()
{
return SteadyClockNS();
}
AUKN_SYM AuUInt64 HighResClockJiffies()
{
return SteadyClockJiffies();
}
#pragma endregion TO_DEPRECATE
} }