[Pharo-project] Preallocation behavior
stephane.ducasse at inria.fr
Thu Apr 28 11:20:01 CEST 2011
tx I prefer that.
On Apr 28, 2011, at 12:17 PM, Henrik Sperre Johansen wrote:
> 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)
> MessageTally spyOn:
> [ 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