summaryrefslogtreecommitdiff
path: root/absl/strings/str_cat_benchmark.cc
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2020-08-17 15:25:15 -0700
committerGravatar vslashg <gfalcon@google.com>2020-08-18 13:12:43 -0400
commitdc969f34a79d019497abb61c2a3f79b5b4be2ea9 (patch)
tree8624fef4728784a788931518c47b3fedc3a3b527 /absl/strings/str_cat_benchmark.cc
parentd0c433455801e1c1fb6f486f0b447e22f946ab52 (diff)
Export of internal Abseil changes
-- caf65de1a20b1ad286796a9eaee38f8b59e93f3b by Samuel Benzaquen <sbenza@google.com>: Add a benchmark for StrAppend. PiperOrigin-RevId: 327111569 -- 2faa53fb3f4090f9609c7dea8951a82e1d72ce3a by Derek Mauro <dmauro@google.com>: 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 <dmauro@google.com>: Re-write the logic for detecting which stacktrace implementation to use on Linux. The visible change is to detect the presence of the `<execinfo.h>` 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 <absl-team@google.com>: Demangle exception spec. PiperOrigin-RevId: 326909460 -- c41b89954545bdc4430d10e785d3ba64a55122d5 by Abseil Team <absl-team@google.com>: Add support for inheriting ctor. PiperOrigin-RevId: 326904919 GitOrigin-RevId: caf65de1a20b1ad286796a9eaee38f8b59e93f3b Change-Id: Ifd28b6a85a032839cbeafd1b16f88046dfd6c1d4
Diffstat (limited to 'absl/strings/str_cat_benchmark.cc')
-rw-r--r--absl/strings/str_cat_benchmark.cc47
1 files changed, 47 insertions, 0 deletions
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 <typename... Chunks>
+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 <typename B>
+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