Performance figures [Re: Idea for a possibly better Collection occurrencesOf method]

Jon Hylands jon at huv.com
Wed Sep 13 20:09:55 UTC 2006


On Wed, 13 Sep 2006 21:35:01 +0200, "Klaus D. Witzel"
<klaus.witzel at cobss.com> wrote:

> > so you don't have to worry about trading off code
> > clarity and re-use for performance.
> 
> I cannot say that I understand this sentence (read it time and again, but  
> no clue). What's the connection.

After having done some simple benchmarks, there doesn't appear to be much
of a difference in the two techniques:

	| time collection sum |
	collection := (1 to: 100000) asOrderedCollection.
	Smalltalk garbageCollect.
	time := Time millisecondsToRun: [sum := collection sum].
	sum.
	time 

versus:

	| time collection sum |
	collection := (1 to: 100000) asOrderedCollection.
	Smalltalk garbageCollect.
	time := Time millisecondsToRun: [
		sum := 0.
		1 to: collection size do: [:index |
			sum := sum + (collection at: index)]].
	sum.
	time 

They both give more or less identical time (about 280 ms on my machine).

It may be that this is a moot point in Squeak...

Later,
Jon

--------------------------------------------------------------
   Jon Hylands      Jon at huv.com      http://www.huv.com/jon

  Project: Micro Seeker (Micro Autonomous Underwater Vehicle)
           http://www.huv.com



More information about the Squeak-dev mailing list