[libcxx-commits] [libcxx] [libc++] Optimize ranges::{for_each, for_each_n} for segmented iterators (PR #132896)
Peng Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jun 7 09:47:26 PDT 2025
================
@@ -33,15 +35,19 @@ int main(int argc, char** argv) {
for ([[maybe_unused]] auto _ : st) {
benchmark::DoNotOptimize(c);
- auto result = for_each(first, last, [](int& x) { x = std::clamp(x, 10, 100); });
+ auto result = for_each(first, last, [](ElemType& x) { x = std::clamp<ElemType>(x, 10, 100); });
benchmark::DoNotOptimize(result);
}
})
->Arg(8)
->Arg(32)
->Arg(50) // non power-of-two
+ ->Arg(1024)
+ ->Arg(4096)
->Arg(8192)
- ->Arg(1 << 20);
+ ->Arg(1 << 14)
+ ->Arg(1 << 16)
+ ->Arg(1 << 18);
----------------
winner245 wrote:
Previously, we were running a test case with a very large `n = (1 << 20)`. To save some time, I replaced this large test case with 3 smaller test cases with `n = (1 << 14)`, `1 << 16`, `1 << 18`. I think the total execution time of these three test cases is actually lower than running a single test case with `n = (1 << 20)`. Please let me know if I misunderstood you.
https://github.com/llvm/llvm-project/pull/132896
More information about the libcxx-commits
mailing list