From fe5ca9dad97b9c9cfa4f81fd25b493b0082ee827 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Thu, 5 Aug 2021 10:30:57 +0200 Subject: [PATCH] unittest: Remove dependency on absl::GetCurrentTimeNanos() Signed-off-by: Stefan Weil --- Makefile.am | 4 ---- unittest/cycletimer.h | 19 ++++++++++--------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Makefile.am b/Makefile.am index 7c6b5393..23391b88 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1173,13 +1173,11 @@ libgtest_main_la_CPPFLAGS = $(libgtest_la_CPPFLAGS) # Build Abseil (needed for some unit tests). check_LTLIBRARIES += libabseil.la libabseil_la_SOURCES = -libabseil_la_SOURCES += abseil/absl/base/internal/cycleclock.cc libabseil_la_SOURCES += abseil/absl/base/internal/raw_logging.cc libabseil_la_SOURCES += abseil/absl/base/internal/spinlock.cc libabseil_la_SOURCES += abseil/absl/base/internal/spinlock_wait.cc libabseil_la_SOURCES += abseil/absl/base/internal/sysinfo.cc libabseil_la_SOURCES += abseil/absl/base/internal/throw_delegate.cc -libabseil_la_SOURCES += abseil/absl/base/internal/unscaledcycleclock.cc libabseil_la_SOURCES += abseil/absl/numeric/int128.cc libabseil_la_SOURCES += abseil/absl/strings/ascii.cc libabseil_la_SOURCES += abseil/absl/strings/charconv.cc @@ -1197,8 +1195,6 @@ libabseil_la_SOURCES += abseil/absl/strings/numbers.cc libabseil_la_SOURCES += abseil/absl/strings/str_cat.cc libabseil_la_SOURCES += abseil/absl/strings/str_split.cc libabseil_la_SOURCES += abseil/absl/strings/string_view.cc -libabseil_la_SOURCES += abseil/absl/time/clock.cc -libabseil_la_SOURCES += abseil/absl/time/duration.cc libabseil_la_CPPFLAGS = -I$(top_srcdir)/abseil GMOCK_INCLUDES = -I$(top_srcdir)/googletest/googlemock/include \ diff --git a/unittest/cycletimer.h b/unittest/cycletimer.h index 6a61a86b..65947fd1 100644 --- a/unittest/cycletimer.h +++ b/unittest/cycletimer.h @@ -13,10 +13,16 @@ #ifndef TESSERACT_UNITTEST_CYCLETIMER_H #define TESSERACT_UNITTEST_CYCLETIMER_H -#include "absl/time/clock.h" // for GetCurrentTimeNanos +#include // for std::chrono // See https://github.com/google/or-tools/blob/master/ortools/base/timer.h class CycleTimer { +private: + static int64_t now() { + return std::chrono::duration_cast( + std::chrono::steady_clock::now().time_since_epoch()).count(); + } + public: CycleTimer() { Reset(); @@ -31,7 +37,7 @@ public: // When Start() is called multiple times, only the most recent is used. void Start() { running_ = true; - start_ = absl::GetCurrentTimeNanos(); + start_ = now(); } void Restart() { @@ -41,17 +47,12 @@ public: void Stop() { if (running_) { - sum_ += absl::GetCurrentTimeNanos() - start_; + sum_ += now() - start_; running_ = false; } } int64_t GetInMs() const { - return GetNanos() / 1000000; - } - -protected: - int64_t GetNanos() const { - return running_ ? absl::GetCurrentTimeNanos() - start_ + sum_ : sum_; + return running_ ? now() - start_ + sum_ : sum_; } private: