<div dir="ltr">Hmm. Looking at the results in a relatively up to date Squeak 4.5:<div><br></div><div><div>[ 10000 timesRepeat: [ | c | c := OrderedCollection new: 100000.</div><div> 1 to: 10000 do: [ :i | c add: i ] ] ] timeToRun 3624</div><div><br></div><div>[ 10000 timesRepeat: [ | c | c := OrderedCollection new: 10000.</div><div> 1 to: 10000 do: [ :i | c add: i ] ] ] timeToRun 2540</div><div><br></div><div>[ 10000 timesRepeat: [ | c | c := OrderedCollection new: 0.</div><div> 1 to: 10000 do: [ :i | c add: i ] ] ] timeToRun 2879</div><div><br></div><div>[ 10000 timesRepeat: [ | c | c := OrderedCollection new: 1000.</div><div> 1 to: 10000 do: [ :i | c add: i ] ] ] timeToRun 2784</div><div><br></div><div>Apparently Squeak takes more time to allocate the large array than Pharo? That would explain why the first run is so much slower than the other 3 - the exact opposite of Max's results (for Pharo 1.3 - but inline with Pharo4 - although not as extreme as Pharo4).</div><div><br></div><div>Then, what about an array that only adds at the beginning (instead of end)? I would expect worse performance - especially if I removed the space at the beginning. WIthout any of those changes, though:</div><div><br></div><div><br></div><div>[ 10000 timesRepeat: [ | c | c := OrderedCollection new: 100000.</div><div> 1 to: 10000 do: [ :i | c addFirst: i ] ] ] timeToRun 2782</div><div><br></div><div>[ 10000 timesRepeat: [ | c | c := OrderedCollection new: 10000.</div><div> 1 to: 10000 do: [ :i | c addFirst: i ] ] ] timeToRun 1845</div><div><br></div><div>[ 10000 timesRepeat: [ | c | c := OrderedCollection new: 0.</div><div> 1 to: 10000 do: [ :i | c addFirst: i ] ] ] timeToRun 2052</div><div><br></div><div>[ 10000 timesRepeat: [ | c | c := OrderedCollection new: 1000.</div><div> 1 to: 10000 do: [ :i | c addFirst: i ] ] ] timeToRun 1962</div><div><br></div><div>Weird that it turned out faster. Maybe it has to do with the first time it runs out of room, it move data (and doesn't allocate a new array?).</div><div><br></div><div>Stephan's code (in the same image):</div><div><br></div><div>[ 10000 timesRepeat: [ | c | c := OrderedCollection new: 100000.</div><div>c add: 1. </div><div>2 to: 10000 do: [ :i | c add: i beforeIndex: (i atRandom) ] ] ] timeToRun 200434</div><div><br></div><div>This last is much slower - every time it adds an value, it forces a copy of the data. It will not be as fast as the others.</div><div><br></div><div>-cbc</div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 14, 2015 at 6:05 AM, Stephan Eggermont <span dir="ltr"><<a href="mailto:stephan@stack.nl" target="_blank">stephan@stack.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm more worried about this part.<br>
<br>
[ 10000 timesRepeat: [ | c |<br>
c := OrderedCollection new.<br>
c add: 1.<br>
<span class=""> 2 to: 10000 do: [ :i |<br>
</span> c add: i beforeIndex: (c atRandom) ] ] ] timeToRun "5 min. 30 s."<br>
<span class="HOEnZb"><font color="#888888"><br>
Stephan<br>
<br>
</font></span></blockquote></div><br></div>