From a67730504d6115786748bbe2a500967a5e40d6aa Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 21 Apr 2020 08:03:06 +0200 Subject: Revert "Revert "There are so many combinations that the libstdc++ library can be buil…"" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vespalib/src/vespa/vespalib/util/time.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'vespalib') diff --git a/vespalib/src/vespa/vespalib/util/time.cpp b/vespalib/src/vespa/vespalib/util/time.cpp index 46cf4806dfc..2e8f4e7e30e 100644 --- a/vespalib/src/vespa/vespalib/util/time.cpp +++ b/vespalib/src/vespa/vespalib/util/time.cpp @@ -52,3 +52,29 @@ Timer::waitAtLeast(duration dur, bool busyWait) { } } + +namespace std::chrono { + +// This is a hack to avoid the slow clock computations on RHEL7/CentOS 7 due to using systemcalls. +// This brings cost down from 550-560ns to 18-19ns + +inline namespace _V2 { + +system_clock::time_point +system_clock::now() noexcept { + timespec tp; + clock_gettime(CLOCK_REALTIME, &tp); + return time_point(duration(chrono::seconds(tp.tv_sec) + + chrono::nanoseconds(tp.tv_nsec))); +} + +steady_clock::time_point +steady_clock::now() noexcept { + timespec tp; + clock_gettime(CLOCK_MONOTONIC, &tp); + return time_point(duration(chrono::seconds(tp.tv_sec) + + chrono::nanoseconds(tp.tv_nsec))); +} + +} +} -- cgit v1.2.3