3 ms·
At worst it makes no difference and at best it makes a big difference - maybe on an input that you didn't even measure!
by IshKebab 3y ago
At 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.