Skip to content

Commit

Permalink
Add new benchmark for integer StrAppend
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 582033534
Change-Id: I9af42210f65b40ccd7f55c9a2e0c8387b69760dc
  • Loading branch information
Abseil Team authored and copybara-github committed Nov 13, 2023
1 parent 483a2d5 commit c046692
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion absl/strings/str_cat_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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}) {
Expand All @@ -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,
Expand Down

0 comments on commit c046692

Please sign in to comment.