Commit c046692a by Abseil Team Committed by Copybara-Service

Add new benchmark for integer `StrAppend`

PiperOrigin-RevId: 582033534
Change-Id: I9af42210f65b40ccd7f55c9a2e0c8387b69760dc
parent 483a2d59
...@@ -154,7 +154,7 @@ void BM_StrAppendImpl(benchmark::State& state, size_t total_bytes, ...@@ -154,7 +154,7 @@ void BM_StrAppendImpl(benchmark::State& state, size_t total_bytes,
} }
void BM_StrAppend(benchmark::State& state) { 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 int chunks_at_a_time = state.range(1);
const absl::string_view kChunk = "0123456789"; const absl::string_view kChunk = "0123456789";
...@@ -174,6 +174,27 @@ void BM_StrAppend(benchmark::State& state) { ...@@ -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> template <typename B>
void StrAppendConfig(B* benchmark) { void StrAppendConfig(B* benchmark) {
for (int bytes : {10, 100, 1000, 10000}) { for (int bytes : {10, 100, 1000, 10000}) {
...@@ -187,6 +208,7 @@ void StrAppendConfig(B* benchmark) { ...@@ -187,6 +208,7 @@ void StrAppendConfig(B* benchmark) {
} }
BENCHMARK(BM_StrAppend)->Apply(StrAppendConfig); BENCHMARK(BM_StrAppend)->Apply(StrAppendConfig);
BENCHMARK(BM_StrAppendInt)->Apply(StrAppendConfig);
template <typename... Chunks> template <typename... Chunks>
void BM_StrCatImpl(benchmark::State& state, void BM_StrCatImpl(benchmark::State& state,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment