From 4e7a5ab70d4e0c72a7702af9fa412974c2b7cc02 Mon Sep 17 00:00:00 2001 From: Alex Rousskov Date: Sun, 13 Oct 2024 16:09:30 -0400 Subject: [PATCH] Found one more place that converts chrono::duration to timeval Old and new code snippets yield the same optimized assembly: https://godbolt.org/z/4rr3WPc9e Old and new getCurrentTime() have nearly identical optimized assembly (with minor differences due to current_time being a global that new getCurrentTime() is still using to compute the other two globals). Both assembly version have eight memory accesses: https://godbolt.org/z/E9hc48G1K The number of assembly operations can be reduced further by not using current_time global to compute current_dtime and squid_curtime: https://godbolt.org/z/4rr3WPc9e --- src/time/gadgets.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/time/gadgets.cc b/src/time/gadgets.cc index d542dfacd4f..865d545ba33 100644 --- a/src/time/gadgets.cc +++ b/src/time/gadgets.cc @@ -25,8 +25,7 @@ getCurrentTime() using namespace std::chrono; const auto now = system_clock::now().time_since_epoch(); - current_time.tv_sec = duration_cast(now).count(); - current_time.tv_usec = duration_cast(now).count() % 1000000; + current_time = ToTimeval(now); current_dtime = (double) current_time.tv_sec + (double) current_time.tv_usec / 1000000.0;