Comment

Comment by nanidin

std::vector::push_back() has a documented complexity issue that occurs if a reallocation must occur as a result of the push (in order to grow the memory backing the vector).

To benchmark this virtual_vec fairly against std::vector, you would need to call std::vector::reserve() with the intended number of items you intend to store in the vector before you start calling std::vector::push_back() in a tight loop.

[0] https://www.cplusplus.com/reference/vector/vector/reserve/

parent nanidin 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton