2 ms·
I just measured a large vector and reserving makes minimal differnce for my case. Ammortized growth is a not slow. Ymmv of course which is why we measure.
by bluGill 3y ago
I just measured a large vector and reserving makes minimal differnce for my case. Ammortized growth is a not slow. Ymmv of course which is why we measure.
- IshKebab 3y agoAt worst it makes no difference and at best it makes a big difference - maybe on an input that you didn't even measure!
- maccard 3y agoAt worst it will make it slower, and at best it will make it faster[0]. The only way to know is to measure with an input that's representative, and this case is exactly why you measure. [0] https://stackoverflow.com/questions/48535727/why-are-c-stl-vectors-1000x-slower-when-doing-many-reserves https://stackoverflow.com/questions/48535727/why-are-c-stl-v...
- bluGill 3y agoWhich is why I measured with many different sizes. I know the fixed size version (the existing code), so I measured with 1 element, half the fixed sized version, the fixed sized version, and double the fixed size version. All with different amounts of reserved data elements. The fixed size version is faster, but not by enough to care about - at least in my case where the vector is created at startup and never changed after.