diff options
author | Abseil Team <absl-team@google.com> | 2023-11-13 11:40:08 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-11-13 11:41:29 -0800 |
commit | c046692abc3163776923095e2009c4e10050f605 (patch) | |
tree | 1842babc81283ebeebe009415c8e2ee15b4955e4 /absl | |
parent | 483a2d59e649179ea9d9bc4d808f6c9d16646f9d (diff) |
Add new benchmark for integer `StrAppend`
PiperOrigin-RevId: 582033534
Change-Id: I9af42210f65b40ccd7f55c9a2e0c8387b69760dc
Diffstat (limited to 'absl')
-rw-r--r-- | absl/strings/str_cat_benchmark.cc | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/absl/strings/str_cat_benchmark.cc b/absl/strings/str_cat_benchmark.cc index b0a86171..36600268 100644 --- a/absl/strings/str_cat_benchmark.cc +++ b/absl/strings/str_cat_benchmark.cc @@ -154,7 +154,7 @@ void BM_StrAppendImpl(benchmark::State& state, size_t total_bytes, } void BM_StrAppend(benchmark::State& state) { - const int total_bytes = state.range(0); + const size_t total_bytes = state.range(0); const int chunks_at_a_time = state.range(1); const absl::string_view kChunk = "0123456789"; @@ -174,6 +174,27 @@ void BM_StrAppend(benchmark::State& state) { } } +void BM_StrAppendInt(benchmark::State& state) { + const size_t total_bytes = state.range(0); + const int chunks_at_a_time = state.range(1); + const size_t kChunk = 1234; + + switch (chunks_at_a_time) { + case 1: + return BM_StrAppendImpl(state, total_bytes, kChunk); + case 2: + return BM_StrAppendImpl(state, total_bytes, kChunk, kChunk); + case 4: + return BM_StrAppendImpl(state, total_bytes, kChunk, kChunk, kChunk, + kChunk); + case 8: + return BM_StrAppendImpl(state, total_bytes, kChunk, kChunk, kChunk, + kChunk, kChunk, kChunk, kChunk, kChunk); + default: + std::abort(); + } +} + template <typename B> void StrAppendConfig(B* benchmark) { for (int bytes : {10, 100, 1000, 10000}) { @@ -187,6 +208,7 @@ void StrAppendConfig(B* benchmark) { } BENCHMARK(BM_StrAppend)->Apply(StrAppendConfig); +BENCHMARK(BM_StrAppendInt)->Apply(StrAppendConfig); template <typename... Chunks> void BM_StrCatImpl(benchmark::State& state, |