aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authortobo <tobo@yandex-team.com>2025-02-10 23:07:18 +0300
committertobo <tobo@yandex-team.com>2025-02-10 23:57:24 +0300
commitcc4962f760e1d454f0ce1dbe54ed92f9bf7eaf6a (patch)
tree139953c2ae965e5ef333734c80a1738d6ab43604 /util
parent1bc386a79e88f4b16c5f3016a36c29564e506bfc (diff)
downloadydb-cc4962f760e1d454f0ce1dbe54ed92f9bf7eaf6a.tar.gz
[util] GmTimeR: speedup a bit
perf before ``` ------------------------------------------------------------------------------- Benchmark Time CPU Iterations ------------------------------------------------------------------------------- BM_GmTimeR 3.61 ns 3.61 ns 194952699 BM_GmTimeRRandom/last_hour 5.04 ns 5.04 ns 136121940 BM_GmTimeRRandom/last_day 5.03 ns 5.03 ns 139883239 BM_GmTimeRRandom/last_month 8.03 ns 8.03 ns 87839823 BM_GmTimeRRandom/last_year 14.9 ns 14.9 ns 46401773 BM_GmTimeRRandom/last_decade 16.9 ns 16.9 ns 41439312 BM_GmTimeRRandom/last_half_centry 16.9 ns 16.9 ns 41225553 ``` perf after ``` ------------------------------------------------------------------------------- Benchmark Time CPU Iterations ------------------------------------------------------------------------------- BM_GmTimeR 3.27 ns 3.27 ns 215390890 BM_GmTimeRRandom/last_hour 4.52 ns 4.52 ns 154869504 BM_GmTimeRRandom/last_day 4.53 ns 4.53 ns 155409964 BM_GmTimeRRandom/last_month 7.24 ns 7.24 ns 96972146 BM_GmTimeRRandom/last_year 13.5 ns 13.5 ns 51957829 BM_GmTimeRRandom/last_decade 15.5 ns 15.5 ns 45192135 BM_GmTimeRRandom/last_half_centry 15.4 ns 15.4 ns 45526906 ``` commit_hash:ac9db56d93a25c3a3018cfbb6bc5800da3d001ee
Diffstat (limited to 'util')
-rw-r--r--util/datetime/systime.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/util/datetime/systime.cpp b/util/datetime/systime.cpp
index d9f31fbc5a..ade1737168 100644
--- a/util/datetime/systime.cpp
+++ b/util/datetime/systime.cpp
@@ -193,11 +193,13 @@ namespace {
days -= DaysSinceEpoch[TableSize - 1];
return TableSize + UNIX_TIME_BASE_YEAR;
}
- ui64 yearIndex = days / DAYS_IN_YEAR;
+ const ui64 yearIndex = days / DAYS_IN_LEAP_YEAR;
// we can miss by at most 1 year
- if (yearIndex > 0 && DaysSinceEpoch[yearIndex - 1] >= days) {
- --yearIndex;
+ Y_ASSERT(yearIndex < TableSize);
+ if (const auto diff = DaysSinceEpoch[yearIndex]; diff <= days) {
+ days -= diff;
+ return static_cast<int>(yearIndex + UNIX_TIME_BASE_YEAR + 1);
}
if (yearIndex > 0) {