[libcxx-commits] [libcxx] [libc++] Optimize string operator[] for known large inputs (PR #69500)

Ilya Tocar via libcxx-commits libcxx-commits at lists.llvm.org
Mon Oct 23 12:40:59 PDT 2023


TocarIP wrote:

For the following benchmark
```
std::string s = "12345678901234567890123456789012345678901234567890";

void BM_index(benchmark::State& state) {
  for (auto _ : state) {
    testing::DoNotOptimize(s[33]*37+s[65]);
  }
}
```
Performance goes from 
```
name      cpu/op 
BM_index  0.69ns ± 1%
```
To 
```
name      cpu/op 
BM_index  0.46ns ± 1%
```
For a ~30% speed-up

https://github.com/llvm/llvm-project/pull/69500


More information about the libcxx-commits mailing list