Hi Jannik,
=== MessageTally spyOn: [ 500 timesRepeat: [ | str | str := WriteStream on: (String new). 9000 timesRepeat: [ str nextPut: $A ]]]. ===
The result appears after 812 ms, which is a large improvement. Now, we could optimize again using the preallocation. Here is my source code:
==== MessageTally spyOn: [ 500 timesRepeat: [ | str | str := WriteStream on: (String new: 10000). 9000 timesRepeat: [ str nextPutAll: 'A' ]]]. ====
In the first case you use nextPut:, in the second case you use nextPutAll:. Replacing nextPutAll: by nextPut: gives me coherent result. 330 ms for the first, and 321 for the second (with the preallocation). Alexandre
And the result is strange: it makes 2 times slower to display the result. The result appears after 1656 ms.
Here is the spy result: === - 1656 tallies, 1656 msec.
**Tree** -------------------------------- Process: (40s) 464519168: nil -------------------------------- **Leaves** 22.9% {380ms} UndefinedObject>>DoIt 22.5% {373ms} SmallInteger(Integer)>>timesRepeat: 22.2% {368ms} WriteStream>>nextPutAll: ===
There is the call of UndefinedObject>>DoIt which is added and takes time. Does anyone know what is done during the preallocation ? Why is it slower than non-preallocation ?
Thanks for your answers. Jannik
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.