Better performance figures for #applyTo:from:to:

Klaus D. Witzel klaus.witzel at cobss.com
Tue Sep 19 06:51:45 UTC 2006


By not using #commonSend and #commonReturn any more is was possible to  
make #applyTo:from:to: have performance close to the inlined #to:do:

Now the price to pay is 0% and general message send is back at top speed.

The new figures are below. Note that #to:do:'s block is inlined by the  
compiler, whereas #applyTo:from:to:'s block doesn't have to be known at  
compile time and that allows greater flexibility.

/Klaus

  | time array sum |
	array := (1 to: 10565520) collect: [:none | 1].
	Smalltalk garbageCollect.
	time := Time millisecondsToRun: [
		sum := 0.
		array do: [:each | sum := sum + each]].
	sum.
	time
=> 4609
  | time array sum |
	array := (1 to: 10565520) collect: [:none | 1].
	Smalltalk garbageCollect.
	time := Time millisecondsToRun: [
		sum := 0.
		array applyTo: [:each | sum := sum + each]
			from: 1 to: array size].
	sum.
	time
=> 2611
  | time array sum |
	array := (1 to: 10565520) collect: [:none | 1].
	Smalltalk garbageCollect.
	time := Time millisecondsToRun: [
		sum := 0.
		1 to: array size do: [:index | sum := sum + (array at: index)]].
	sum.
	time
=> 2033




More information about the Squeak-dev mailing list