diff options
author | Abseil Team <absl-team@google.com> | 2023-09-19 09:07:16 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-09-19 09:08:13 -0700 |
commit | bd467aada0817a4f95d1629afdbb881b1e2c9fec (patch) | |
tree | 0159c2cc4c32868e2d908f67b26525adfdc28500 /absl/strings | |
parent | cffc9ef2b1174dea2b78cbf5efeeaea1606ad25b (diff) |
Additional StrCat microbenchmarks.
PiperOrigin-RevId: 566650311
Change-Id: Ibfabee88ea9999d08ade05ece362f5a075d19695
Diffstat (limited to 'absl/strings')
-rw-r--r-- | absl/strings/str_cat_benchmark.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/absl/strings/str_cat_benchmark.cc b/absl/strings/str_cat_benchmark.cc index e54a9230..b0a86171 100644 --- a/absl/strings/str_cat_benchmark.cc +++ b/absl/strings/str_cat_benchmark.cc @@ -188,6 +188,35 @@ void StrAppendConfig(B* benchmark) { BENCHMARK(BM_StrAppend)->Apply(StrAppendConfig); +template <typename... Chunks> +void BM_StrCatImpl(benchmark::State& state, + Chunks... chunks) { + for (auto s : state) { + std::string result = absl::StrCat(chunks...); + benchmark::DoNotOptimize(result); + } +} + +void BM_StrCat(benchmark::State& state) { + const int chunks_at_a_time = state.range(0); + const absl::string_view kChunk = "0123456789"; + + switch (chunks_at_a_time) { + case 1: + return BM_StrCatImpl(state, kChunk); + case 2: + return BM_StrCatImpl(state, kChunk, kChunk); + case 3: + return BM_StrCatImpl(state, kChunk, kChunk, kChunk); + case 4: + return BM_StrCatImpl(state, kChunk, kChunk, kChunk, kChunk); + default: + std::abort(); + } +} + +BENCHMARK(BM_StrCat)->Arg(1)->Arg(2)->Arg(3)->Arg(4); + void BM_StrCat_int(benchmark::State& state) { int i = 0; for (auto s : state) { |