[libcxx-commits] [libcxx] [libc++] Fold __search_substring into _Traits::find in case the second string has length 1 (PR #160076)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Sep 23 07:37:28 PDT 2025
================
@@ -60,6 +60,45 @@ static void BM_StringFindMatch2(benchmark::State& state) {
}
BENCHMARK(BM_StringFindMatch2)->Range(1, MAX_STRING_LEN / 4);
+static void BM_string_literal(benchmark::State& state) {
+ std::string s;
+
+ for (int i = 0; i < state.range(0); i++)
+ s += 'a';
+
+ s += 'b';
+
+ benchmark::DoNotOptimize(s.data());
+ benchmark::ClobberMemory();
+ size_t pos;
+
+ for (auto _ : state) {
+ benchmark::DoNotOptimize(pos = s.find("b")); // "b" is a string literal, it should be longer
+ benchmark::ClobberMemory();
+ }
+}
+
+BENCHMARK(BM_string_literal)->RangeMultiplier(2)->Range(8, 8 << 10);
+
+static void BM_char_literal(benchmark::State& state) {
----------------
ldionne wrote:
```suggestion
static void BM_StringFindCharLiteral(benchmark::State& state) {
```
https://github.com/llvm/llvm-project/pull/160076
More information about the libcxx-commits
mailing list