[Cuis-dev] performance of OrderedCollection #new vs. #new:

Christian Haider mail at christianhaider.de
Sun Mar 3 10:36:32 PST 2024


Hi,

 

I was going to complain that #new: on OrderedCollection was removed.

I thought that it is common wisdom that #new: is a very important
optimization when allocating OrderedCollections, especially big ones.

 

Therefore, I measured the differences with the following script:

| time time1 time2 |

(0 to: 100000 by: 1000) collect: [:size |

     time := time1 := time2 := 0.

     1000 timesRepeat: [

           time := time + (Time microsecondsToRun: [

                | list |

                list := OrderedCollection new.

                1 to: size do: [:i | list add: i]])].

     time1 := time / 1000.

     time := 0.

     1000 timesRepeat: [

           time := time + (Time microsecondsToRun: [

                | list |

                list := OrderedCollection new: size.

                1 to: size do: [:i | list add: i]])].

     time2 := time / 1000.

     Array with: size with: time1 with: time2]

 

I ran the script with the current Cuis 6.3, Pharo 10, Squeak 6.0 and VW
9.3.1.

The results are in the attached file from which I created the charts below
with Excel.

The size of the created collections are on the x-axis, while the y-axis
shows the microseconds.

 

The results are interesting!

1.	As expected, VW new: is the fastest and grows linear with the
collection size.
2.	As expected, #new is slower than #new: (except for Cuis - more
below)
3.	There are certain threshold sizes from which on the creation is
consistently slower (look at 40,000 and 82,000 for #new:)
4.	Surprising is the slowness of Pharo(?)

 



 

Extremely surprising is Cuis. The next chart shows just Cuis and Squeak to
spread the scale a bit.

In Cuis, both methods have about the same performance and are growing linear
with the size!!!

 

How is this possible? What is the magic? Or is the measurement wrong? 

I am quite impressed.

And I am not going to complain about the missing #new: :).

 

Happy hacking,

Christian

 

 



 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240303/47fd2ff3/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 60052 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240303/47fd2ff3/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image006.png
Type: image/png
Size: 43991 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240303/47fd2ff3/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OCPerformance.csv
Type: application/vnd.ms-excel
Size: 4369 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240303/47fd2ff3/attachment-0001.xlb>


More information about the Cuis-dev mailing list