I timed some code recently and found that .reserve made almost no improvement when appending. It appears that the actual change to the length by the append had a very high overhead of something over 200 instructions executed, regardless if the .reserve was done. This was a simple append to an integer array.

The only way I found to avoid this was to set the length outside the loop and update the array values by index. That was on the order of 10x faster.



Reply via email to