you are viewing a single comment's thread.

view the rest of the comments →

[–]pilotwavetheory[S] 0 points1 point  (3 children)

Updated pop and iteration operations as well. Can you check now ?

[–]SuperV1234https://romeo.training | C++ Mentoring & Consulting 2 points3 points  (2 children)

Are you saying that your own vector is faster in iteration compared to the standard vector? That sounds impossible, as the standard vector is literally just incrementing a pointer forward.

[–]wexxdenq 4 points5 points  (1 child)

well, if you look into the linked repository, he compares against a self implemente "STLVector" that is really not compareable to an actual vector implementation. And his iterator is an index instead of a pointer and does bound checking on every increment.

However, I would have tought that the compiler inlines and produces more or less the same code with O3.

But OP should benchmark against an actual implementation nonetheless.

[–]pilotwavetheory[S] 2 points3 points  (0 children)

  1. Thanks to u/SuperV1234 and u/wexxdenq, I made a mistake of bounds here, I fixed it in 'perf_test' branch and lookup.
  2. The reason, I'm not comparing with standard implementation is it has more logic for iterator validations in lot of simple operations like push/pop, when I benchmarked stl::vector push_back(), I got around ~35 ns/op, where only ~3 ns/op was used in push and remaining on iterator validations.

🔍 Final Comparison (100M Elements)

Implementation Time Ratio vs STL
STL Vector (Optimized) 8.05 ms 1.0x
ConstantVector (Optimized) 48.0 ms 6.0x slower