[squeak-dev] Re: benchmarks
nicolas cellier
ncellier at ifrance.com
Tue Mar 18 21:49:56 UTC 2008
nicolas cellier a écrit :
> nicolas cellier a écrit :
>>
>> Don't know if it fits the rules of the game however...
>>
>
> Of course not.
>
>
>
However, it's still very easy to improve Squeak sieve:
inside loop that set all multiple to false IS NOT OPTIMIZED!
MessageNode>>transformToDo:
arguments size = 3
ifTrue: [increment _ arguments at: 2.
(increment isConstantNumber and:
[increment literalValue ~= 0]) ifFalse: [^ false]]
ifFalse: [increment _ encoder encodeLiteral: 1].
Well, increment is a temporary variable, not a literal constant...
So transformToDo: refuses to optimize.
So a much faster Squeak sieve that fits game rules is:
[Time millisecondsToRun: [| n k count isPrime |
n := (1 bitShift: 9) * 10000.
count := 0.
isPrime := Array new: n withAll: true.
2 to: n do:
[:i |
(isPrime at: i) ifTrue:
[k := i.
[(k := k+i) > n] whileFalse: [isPrime at: k put: false].
count := count + 1]].
count
]] ensure: [Smalltalk garbageCollect.]
More information about the Squeak-dev
mailing list
|