diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/system/hp_timer.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/system/hp_timer.cpp')
-rw-r--r-- | util/system/hp_timer.cpp | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/util/system/hp_timer.cpp b/util/system/hp_timer.cpp index e4c3f21e6b..27f97a9b2b 100644 --- a/util/system/hp_timer.cpp +++ b/util/system/hp_timer.cpp @@ -1,104 +1,104 @@ #include "hp_timer.h" - + #include <util/generic/algorithm.h> -#include <util/generic/singleton.h> -#include <util/datetime/cputimer.h> - +#include <util/generic/singleton.h> +#include <util/datetime/cputimer.h> + using namespace NHPTimer; -namespace { - struct TFreq { - inline TFreq() - : Freq(InitHPTimer()) +namespace { + struct TFreq { + inline TFreq() + : Freq(InitHPTimer()) , Rate(1.0 / Freq) , CyclesPerSecond(static_cast<ui64>(Rate)) - { + { } - - static inline const TFreq& Instance() { + + static inline const TFreq& Instance() { return *SingletonWithPriority<TFreq, 1>(); } - static double EstimateCPUClock() { - for (;;) { + static double EstimateCPUClock() { + for (;;) { ui64 startCycle = 0; ui64 startMS = 0; - + for (;;) { startMS = MicroSeconds(); startCycle = GetCycleCount(); - + ui64 n = MicroSeconds(); if (n - startMS < 100) { break; } - } - + } + Sleep(TDuration::MicroSeconds(5000)); - + ui64 finishCycle = 0; ui64 finishMS = 0; - + for (;;) { finishMS = MicroSeconds(); - + if (finishMS - startMS < 100) { continue; } - + finishCycle = GetCycleCount(); - + ui64 n = MicroSeconds(); - + if (n - finishMS < 100) { break; } - } + } if (startMS < finishMS && startCycle < finishCycle) { return (finishCycle - startCycle) * 1000000.0 / (finishMS - startMS); } - } - } - - static double InitHPTimer() { - const size_t N_VEC = 9; - - double vec[N_VEC]; - + } + } + + static double InitHPTimer() { + const size_t N_VEC = 9; + + double vec[N_VEC]; + for (auto& i : vec) { i = EstimateCPUClock(); - } - - Sort(vec, vec + N_VEC); - - return 1.0 / vec[N_VEC / 2]; - } - - inline double GetSeconds(const STime& a) const { - return static_cast<double>(a) * Freq; - } - - inline double GetClockRate() const { + } + + Sort(vec, vec + N_VEC); + + return 1.0 / vec[N_VEC / 2]; + } + + inline double GetSeconds(const STime& a) const { + return static_cast<double>(a) * Freq; + } + + inline double GetClockRate() const { return Rate; - } - + } + inline ui64 GetCyclesPerSecond() const { return CyclesPerSecond; } - const double Freq; + const double Freq; const double Rate; const ui64 CyclesPerSecond; - }; + }; } double NHPTimer::GetSeconds(const STime& a) noexcept { - return TFreq::Instance().GetSeconds(a); + return TFreq::Instance().GetSeconds(a); } double NHPTimer::GetClockRate() noexcept { - return TFreq::Instance().GetClockRate(); + return TFreq::Instance().GetClockRate(); } ui64 NHPTimer::GetCyclesPerSecond() noexcept { @@ -111,8 +111,8 @@ void NHPTimer::GetTime(STime* pTime) noexcept { double NHPTimer::GetTimePassed(STime* pTime) noexcept { STime old(*pTime); - + *pTime = GetCycleCount(); - + return GetSeconds(*pTime - old); } |