relative benefit of .reserve and .length
Jay Norwood via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Apr 28 05:56:24 PDT 2016
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.
More information about the Digitalmars-d-learn
mailing list