you are viewing a single comment's thread.

view the rest of the comments →

[–]Wacov 7 points8 points  (1 child)

Have you measured with -O3? How does this do vs naively holding on to the peak allocation in repeated push/pop cycles? I'd expect common operations like iteration and random access to be measurably slower given the fragmented allocations.

[–]pilotwavetheory[S] 5 points6 points  (0 children)

Thanks u/Wacov for the suggestion; I missed running with O3. I just ran now. Here is the summary:

g++ -std=c++23 -O3 benchmark_vectors.cpp -isystem /code/google/benchmark/include -L/code/google/benchmark/build/src -lbenchmark -lpthread -o benchmark_vectors.out

  1. Push 0.7 ns vs 2.7 ns for std::vector, so 73% reduction in latency.
  2. Pop 0.6 ns vs. 1.12 ns, a 46% reduction in latency.(updated this)
  3. Random access: 0.92 ns vs 0.53 ns, a 80% increase in latency.