[libcxx-commits] [libcxx] [libc++][ranges] optimize the performance of `ranges::starts_with` (PR #84570)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 27 07:55:34 PDT 2025
ldionne wrote:
When benchmarking locally, I get the following results for `std::vector`:
```
Comparing build/default/libcxx/test/benchmarks/algorithms/nonmodifying/Output/starts_with.bench.cpp.dir/benchmark-result.json to build/candidate/libcxx/test/benchmarks/algorithms/nonmodifying/Output/starts_with.bench.cpp.dir/benchmark-result.json
Benchmark Time CPU Time Old Time New CPU Old CPU New
------------------------------------------------------------------------------------------------------------------------------------
rng::starts_with(vector<int>)/8 -0.0314 -0.0314 2 2 2 2
rng::starts_with(vector<int>)/1000 +0.1724 +0.1719 99 116 99 115
rng::starts_with(vector<int>)/1024 +0.1791 +0.1791 101 119 101 119
rng::starts_with(vector<int>)/8192 +0.1894 +0.1893 821 976 821 976
rng::starts_with(vector<int>)/1048576 +0.0984 +0.0984 113321 124466 113308 124457
OVERALL_GEOMEAN +5.1211 +5.1148 0 0 0 0
```
Using `ranges::equal` seems to be consistently worse than using `ranges::mismatch`.
https://github.com/llvm/llvm-project/pull/84570
More information about the libcxx-commits
mailing list