about summary refs log tree commit diff
path: root/absl/strings/str_split_benchmark.cc
diff options
context:
space:
mode:
Diffstat (limited to 'absl/strings/str_split_benchmark.cc')
-rw-r--r--absl/strings/str_split_benchmark.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/absl/strings/str_split_benchmark.cc b/absl/strings/str_split_benchmark.cc
index 28c25e8d354b..f38dfcfe5af7 100644
--- a/absl/strings/str_split_benchmark.cc
+++ b/absl/strings/str_split_benchmark.cc
@@ -44,6 +44,29 @@ void BM_Split2StringView(benchmark::State& state) {
 }
 BENCHMARK_RANGE(BM_Split2StringView, 0, 1 << 20);
 
+static const absl::string_view kDelimiters = ";:,.";
+
+std::string MakeMultiDelimiterTestString(int desired_length) {
+  static const int kAverageValueLen = 25;
+  std::string test(desired_length * kAverageValueLen, 'x');
+  for (int i = 0; i * kAverageValueLen < test.size(); ++i) {
+    // Cycle through a variety of delimiters.
+    test[i * kAverageValueLen] = kDelimiters[i % kDelimiters.size()];
+  }
+  return test;
+}
+
+// Measure StrSplit with ByAnyChar with four delimiters to choose from.
+void BM_Split2StringViewByAnyChar(benchmark::State& state) {
+  std::string test = MakeMultiDelimiterTestString(state.range(0));
+  for (auto _ : state) {
+    std::vector<absl::string_view> result =
+        absl::StrSplit(test, absl::ByAnyChar(kDelimiters));
+    benchmark::DoNotOptimize(result);
+  }
+}
+BENCHMARK_RANGE(BM_Split2StringViewByAnyChar, 0, 1 << 20);
+
 void BM_Split2StringViewLifted(benchmark::State& state) {
   std::string test = MakeTestString(state.range(0));
   std::vector<absl::string_view> result;