From dc969f34a79d019497abb61c2a3f79b5b4be2ea9 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 17 Aug 2020 15:25:15 -0700 Subject: Export of internal Abseil changes -- caf65de1a20b1ad286796a9eaee38f8b59e93f3b by Samuel Benzaquen : Add a benchmark for StrAppend. PiperOrigin-RevId: 327111569 -- 2faa53fb3f4090f9609c7dea8951a82e1d72ce3a by Derek Mauro : Add the inline namespace to the code generated by gaussian_distribution_gentables A previous changed manually added it to the output PiperOrigin-RevId: 327022780 -- 29edfd86e49e4d7665e843463f8df3c72467e909 by Derek Mauro : Re-write the logic for detecting which stacktrace implementation to use on Linux. The visible change is to detect the presence of the `` header, which allows using the `backtrace`-based implementation when it is available. The logic has been simplified as well. Fixes #746 PiperOrigin-RevId: 326911875 -- ce198204b77aac240e98fc8d5931b17a8b26bac3 by Abseil Team : Demangle exception spec. PiperOrigin-RevId: 326909460 -- c41b89954545bdc4430d10e785d3ba64a55122d5 by Abseil Team : Add support for inheriting ctor. PiperOrigin-RevId: 326904919 GitOrigin-RevId: caf65de1a20b1ad286796a9eaee38f8b59e93f3b Change-Id: Ifd28b6a85a032839cbeafd1b16f88046dfd6c1d4 --- absl/strings/str_cat_benchmark.cc | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'absl/strings/str_cat_benchmark.cc') diff --git a/absl/strings/str_cat_benchmark.cc b/absl/strings/str_cat_benchmark.cc index ee4ad112..02c4dbe6 100644 --- a/absl/strings/str_cat_benchmark.cc +++ b/absl/strings/str_cat_benchmark.cc @@ -137,4 +137,51 @@ void BM_DoubleToString_By_SixDigits(benchmark::State& state) { } BENCHMARK(BM_DoubleToString_By_SixDigits); +template +void BM_StrAppendImpl(benchmark::State& state, size_t total_bytes, + Chunks... chunks) { + for (auto s : state) { + std::string result; + while (result.size() < total_bytes) { + absl::StrAppend(&result, chunks...); + benchmark::DoNotOptimize(result); + } + } +} + +void BM_StrAppend(benchmark::State& state) { + const int total_bytes = state.range(0); + const int chunks_at_a_time = state.range(1); + const absl::string_view kChunk = "0123456789"; + + 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 +void StrAppendConfig(B* benchmark) { + for (int bytes : {10, 100, 1000, 10000}) { + for (int chunks : {1, 2, 4, 8}) { + // Only add the ones that divide properly. Otherwise we are over counting. + if (bytes % (10 * chunks) == 0) { + benchmark->Args({bytes, chunks}); + } + } + } +} + +BENCHMARK(BM_StrAppend)->Apply(StrAppendConfig); + } // namespace -- cgit v1.2.3