Performance figures [Re: Idea for a possibly better Collection
occurrencesOf method]
Klaus D. Witzel
klaus.witzel at cobss.com
Wed Sep 13 22:36:09 UTC 2006
Sorry Jon, you timed boxing of LargeIntegers (and perhaps garbage
collection of the boxes). In the below the number 10565520 is short for
the interval I suggested, 1 to: (0.5 * SmallInteger maxVal) sqrt truncated
* 456.
Almost factor 5, that's what I expected (asymptotically 6). My other
demoes did almost nothing inside the loops.
So: should we care and ask the VM what she can do better than that ;-)
/Klaus
| time collection sum |
collection := (1 to: 10565520) collect: [:none | 1].
Smalltalk garbageCollect.
time := Time millisecondsToRun: [
sum := 0.
1 to: collection size do: [:index |
sum := sum + (collection at: index)]].
sum.
time
=> 2096
| time collection sum |
collection := (1 to: 10565520) collect: [:none | 1].
Smalltalk garbageCollect.
time := Time millisecondsToRun: [sum := collection sum].
sum.
time
=> 9681
On Wed, 13 Sep 2006 22:09:55 +0200, Jon Hylands wrote:
> 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
|