Skip to content

Commit

Permalink
Found one more place that converts chrono::duration to timeval
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rousskov committed Oct 13, 2024
1 parent df12c15 commit 4e7a5ab
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/time/gadgets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ getCurrentTime()
using namespace std::chrono;
const auto now = system_clock::now().time_since_epoch();

current_time.tv_sec = duration_cast<seconds>(now).count();
current_time.tv_usec = duration_cast<microseconds>(now).count() % 1000000;
current_time = ToTimeval(now);

current_dtime = (double) current_time.tv_sec +
(double) current_time.tv_usec / 1000000.0;
Expand Down

0 comments on commit 4e7a5ab

Please sign in to comment.