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

Klaus D. Witzel klaus.witzel at cobss.com
Wed Sep 13 16:10:30 UTC 2006


The following two demoes show a factor of ca. 3 in their timeToRun. The  
first sends #to:do: for the iteration, the other does just its inlined  
bytecodes. The blocks are not noop and compute and return the same (same  
also in the respective #to:do:).

Expression (0.5 * SmallInteger maxVal) sqrt truncated * 456 means: just  
use SmallIntegers, no boxed LargeIntegers. You can adjust the 456  
parameter to your machine, timeToRun should not show less than 1,000 in  
either case. Doing a garbageCollect removed some nervousity with smaller  
runs here.

------------
| aBlock |
  aBlock := [:int | int + 1 ].
  Smalltalk garbageCollect.
  [1 to: (0.5 * SmallInteger maxVal) sqrt truncated * 456 do: aBlock]  
timeToRun
=> 3707
------------
  Smalltalk garbageCollect.
  [1 to: (0.5 * SmallInteger maxVal) sqrt truncated * 456 do: [:int | int  
+ 1 ]] timeToRun
=> 1274
------------

I doubt that a primitive implementation would show a significantly better  
factor, because the VM already is fast! and because in practice the  
#to:do: intervals are usually smaller than in the above. The only  
difference I saw in the bytecodes was related to the #to:do: and #value:  
message send.

Is the above what the community expects, have better demoes, how's it on  
your platform (have windoze XP here).

/Klaus

On Tue, 12 Sep 2006 12:19:02 +0200, Jon Hylands wrote:

> On Tue, 12 Sep 2006 09:31:40 +0200, "Klaus D. Witzel"
> <klaus.witzel at cobss.com> wrote:
>
>> Whatever "better" method is used, they all have to send the #do: message
>> and so:
>>
>> - #do: must be fastest
>> - users of #do: must be slower than pure #do:
>
> A while ago, the guys at IBM did a very interesting performance upgrade  
> to
> VisualAge Smalltalk - they "fixed" the standard enumeration methods so  
> they
> all have (more or less) identical performance. They wrote a collection
> iterator primitive method in BlockContext:
>
> apply: aCollection from: start to: end
>
> This method calls an iterator primitive, and all the collection iterators
> end up calling this method, and it has taken away pretty much all the
> performance differences between using #to:do:, #do:, #select:,
> #inject:into:, etc.
>
> It used to be that the only way to get fast collection iteration was to  
> use
> #to:do: (because it is inlined). Now they all run at the same speed,  
> which
> is really fast.
>
> 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