[squeak-dev] benchmarks

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[squeak-dev] benchmarks

Pavel Krivanek
Hi,

I've found The Computer Language Benchmarks Game sandbox that includes
several tests for Squeak too. See

http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=all&lang=all

Cheers,
-- Pavel

Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: benchmarks

Nicolas Cellier-3
Pavel Krivanek a écrit :

> Hi,
>
> I've found The Computer Language Benchmarks Game sandbox that includes
> several tests for Squeak too. See
>
> http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=all&lang=all
>
> Cheers,
> -- Pavel
>
>

Fun.

Sure it can be improved at cost of more lines of code.

For example, sieve algorithm does not need to start at: i+i, but at i*i.

Time millisecondsToRun: [| n count isPrime |
    n := (1 bitShift: 9) * 10000.
    count := 0.
    isPrime := Array new: n withAll: true.
    2 to: n do:
       [:i |
       (isPrime at: i) ifTrue:
          [i + i to: n by: i do:
             [:k | isPrime at: k put: false].
          count := count + 1]].
    count
]

This unfortunately slow things down due to LargeInteger.
So multiples must not be tested above n sqrt,
and n sqrt < (1 bitShift: n hightBit // 2 + 1),
so a faster sieve would be

Time millisecondsToRun: [| n count isPrime nmax |
    n := (1 bitShift: 9) * 10000.
    count := 0.
    isPrime := Array new: n withAll: true.
    nmax := (1 bitShift: n highBit // 2 + 1) min: n.
    2 to: nmax do:
       [:i |
       (isPrime at: i) ifTrue:
          [i * i to: n by: i do:
             [:k | isPrime at: k put: false].
          count := count + 1]].
    nmax + 1 to: n do:
       [:i |
       (isPrime at: i) ifTrue:
          [count := count + 1]].
    count
]

Don't know if it fits the rules of the game however...

Nicolas


Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: benchmarks

Nicolas Cellier-3
nicolas cellier a écrit :
>
> Don't know if it fits the rules of the game however...
>

Of course not.


Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Re: benchmarks

Nicolas Cellier-3
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.]