aboutsummaryrefslogtreecommitdiffstats
path: root/util/datetime/benchmark/format
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-03-22 18:57:39 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-03-22 19:07:02 +0300
commit3440878efbe2d889da7070f8f8c1f09c7d162a68 (patch)
tree78d4a3e0677bf6c35ec3997d176502f00b7ef862 /util/datetime/benchmark/format
parente20d8d7107fe83f612b832be904fac0257138f30 (diff)
downloadydb-3440878efbe2d889da7070f8f8c1f09c7d162a68.tar.gz
Intermediate changes
Diffstat (limited to 'util/datetime/benchmark/format')
-rw-r--r--util/datetime/benchmark/format/main.cpp59
-rw-r--r--util/datetime/benchmark/format/ya.make12
2 files changed, 71 insertions, 0 deletions
diff --git a/util/datetime/benchmark/format/main.cpp b/util/datetime/benchmark/format/main.cpp
new file mode 100644
index 0000000000..9c930d4714
--- /dev/null
+++ b/util/datetime/benchmark/format/main.cpp
@@ -0,0 +1,59 @@
+#include <library/cpp/testing/gbenchmark/benchmark.h>
+
+#include <util/datetime/base.h>
+#include <util/stream/str.h>
+
+class TTimestampGenerator {
+public:
+ TInstant operator()() {
+ TInstant result = TInstant::MicroSeconds(Base_ + Current_);
+ Current_ = (Current_ + Step_) % Range_;
+ return result;
+ }
+
+private:
+ static constexpr ui64 Step_ = TDuration::MicroSeconds(1234567891011).MicroSeconds();
+ static constexpr ui64 Range_ = 1ull << 45; // ~ year
+ static constexpr ui64 Base_ = TInstant::Seconds(1605320321).MicroSeconds();
+ ui64 Current_ = 0;
+};
+
+Y_FORCE_INLINE static void BenchFormatStream(auto&& formatFn, benchmark::State& state) {
+ TTimestampGenerator gen;
+ TStringStream ss;
+ for (auto _ : state) {
+ ss << formatFn(gen());
+ Y_DO_NOT_OPTIMIZE_AWAY(ss.Str());
+ ss.clear();
+ }
+}
+
+Y_FORCE_INLINE static void BenchToString(auto&& toStringFn, benchmark::State& state) {
+ TTimestampGenerator gen;
+ TString s;
+ for (auto _ : state) {
+ s = toStringFn(gen());
+ Y_DO_NOT_OPTIMIZE_AWAY(s);
+ }
+}
+
+void BM_FormatIsoLocal(benchmark::State& state) {
+ BenchFormatStream(FormatIsoLocal, state);
+}
+
+void BM_FormatLocal(benchmark::State& state) {
+ BenchFormatStream(FormatLocal, state);
+}
+
+void BM_ToStringIsoLocal(benchmark::State& state) {
+ BenchToString(std::mem_fn(&TInstant::ToIsoStringLocal), state);
+}
+
+void BM_ToStringLocal(benchmark::State& state) {
+ BenchToString(std::mem_fn(&TInstant::ToIsoStringLocal), state);
+}
+
+BENCHMARK(BM_FormatIsoLocal);
+BENCHMARK(BM_FormatLocal);
+BENCHMARK(BM_ToStringIsoLocal);
+BENCHMARK(BM_ToStringLocal);
diff --git a/util/datetime/benchmark/format/ya.make b/util/datetime/benchmark/format/ya.make
new file mode 100644
index 0000000000..ef5e7b0c93
--- /dev/null
+++ b/util/datetime/benchmark/format/ya.make
@@ -0,0 +1,12 @@
+SUBSCRIBER(g:util-subscribers)
+
+G_BENCHMARK()
+
+PEERDIR(
+)
+
+SRCS(
+ main.cpp
+)
+
+END()