[Pharo-project] Preallocation behavior
Henrik Sperre Johansen
henrik.s.johansen at veloxit.no
Thu Apr 28 12:17:15 CEST 2011
On 28.04.2011 10:49, Stéphane Ducasse wrote:
> you lost me
>> In the first example, you are making a single string with all A's of size 9000 repeated 500 times.
>> In the second example, you are making 9000 strings with all A's of size 10000 repeated 500 times.
My bad, I misread and thought the code was using atAllPut: , like it
should :) (that is, if its intent is to initialize a presized collection
with default values)
[ 500 timesRepeat: [
| str |
str :=String new: 9000.
str atAllPut: $A ]].
only takes a couple of milliseconds.
As for nextPut: vs nextPutAll:, that is to be expected.
nextPutAll: is optimized for sizes> 1, on my machine it "catches up" when you surpass 4 characters added in each loop.
More information about the Pharo-project