[libcxx-commits] [libcxx] [libc++] Add some _LIBCPP_ASSUMEs for bounded iterators (PR #109033)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Nov 28 11:21:25 PST 2024
================
@@ -101,10 +101,26 @@ struct __bounded_iter {
_LIBCPP_HIDE_FROM_ABI
----------------
ldionne wrote:
Not attached to this line: Could you please add a benchmark in e.g. `libcxx/test/benchmarks/vector_operations.bench.cpp` (and `deque` while we're at it) that does a simple use of iterators? This could be added in e.g. `libcxx/test/benchmarks/ContainerBenchmarks.h`:
```c++
template <class T>
TEST_NOINLINE void use(T&) {}
template <class Container, class GenInputs>
void BM_iterate_whole_container(benchmark::State& st, Container c, GenInputs gen) {
auto in = gen(st.range(0));
c.assign(in.begin(), in.end());
benchmark::DoNotOptimize(&c);
benchmark::DoNotOptimize(&in);
for (auto _ : st) {
for (auto it = c.begin(); it != c.end(); ++it) {
use(*it);
}
benchmark::ClobberMemory();
}
}
```
I'm not sure this works as-is, but you get the idea. Basically this would be a benchmark whose goal is to go through the whole container without doing much, just to exercise the iterators themselves.
Then, by running it as:
```
./libcxx/utils/libcxx-lit build/generic-hardening-mode-fast-with-abi-breaks -sv libcxx/test/benchmarks/vector_operations.bench.cpp --param optimization=speed
```
before and after your change, we should hopefully be able to see some sort of difference?
https://github.com/llvm/llvm-project/pull/109033
More information about the libcxx-commits
mailing list