diff options
author | Abseil Team <absl-team@google.com> | 2024-02-27 04:34:27 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-02-27 04:35:39 -0800 |
commit | bde089f91c7da54aea5b3694c6ce58cb020e06fe (patch) | |
tree | e8f71b4ef0794f1ddc80b64c1d96567e71a09351 /absl/synchronization/internal/kernel_timeout_test.cc | |
parent | 90ebb6fca0932e33f278d31d42101bb242b7dc7c (diff) | |
download | abseil-bde089f91c7da54aea5b3694c6ce58cb020e06fe.tar.gz abseil-bde089f91c7da54aea5b3694c6ce58cb020e06fe.tar.bz2 abseil-bde089f91c7da54aea5b3694c6ce58cb020e06fe.zip |
Optimize `absl::Duration` division and modulo: Allow the compiler to inline `time_internal::IDivDuration`, by splitting the slow path to a separate function.
With that change, the compiler can inline the fast path. This is specially important in the context of `Duration::operator%=`, because it allows proving that the return value is unused, therefore avoiding expensive multiplies and divides (e.g. `*q = num_hi / den_hi;`).
```
name old cpu/op new cpu/op delta
BM_Duration_Modulo 23.1ns ± 0% 22.5ns ± 0% -2.42% (p=0.000 n=20+16)
BM_Duration_Modulo_FastPath 7.05ns ± 0% 4.85ns ± 0% -31.17% (p=0.000 n=20+20)
name old time/op new time/op delta
BM_Duration_Modulo 23.1ns ± 0% 22.6ns ± 0% -2.43% (p=0.000 n=20+16)
BM_Duration_Modulo_FastPath 7.06ns ± 0% 4.86ns ± 0% -31.18% (p=0.000 n=20+20)
name old INSTRUCTIONS/op new INSTRUCTIONS/op delta
BM_Duration_Modulo 188 ± 0% 178 ± 0% -5.32% (p=0.000 n=20+20)
BM_Duration_Modulo_FastPath 84.0 ± 0% 62.0 ± 0% -26.19% (p=0.000 n=20+20)
name old CYCLES/op new CYCLES/op delta
BM_Duration_Modulo 73.8 ± 0% 72.1 ± 0% -2.27% (p=0.000 n=19+20)
BM_Duration_Modulo_FastPath 22.5 ± 0% 15.5 ± 0% -31.13% (p=0.000 n=19+20)
```
Note: We don't need to expose `absl::time_internal::IDivDuration` at all given that we have a public `absl::IDivDuration`.
PiperOrigin-RevId: 610710635
Change-Id: Ief7c3d5b1c000b397d931e9249edcaef96e7151e
Diffstat (limited to 'absl/synchronization/internal/kernel_timeout_test.cc')
0 files changed, 0 insertions, 0 deletions