Can Squeak be faster than Java? Yes :-)

Klaus D. Witzel klaus.witzel at cobss.com
Fri Feb 16 22:06:16 UTC 2007


Here too, Squeak's VM (which, BTW, does all that context memory allocation  
per send) is 50% better than the static's VM :)

And it does only a bit better after you force class loading (i/o !) before  
the timed loop

     {java.io.PrintStream p = System.out;}
     {java.lang.Throwable t = new ArithmeticException();}

and replace Exception by ArithmeticException (and ZeroDivide).

FWIW, I think that the main reason for this difference is the heavy string  
processing in the vendor's libraries, once per exception thrown.

/Klaus

On Fri, 16 Feb 2007 22:03:20 +0100, Pavel Krivanek  
<squeak1 at continentalbrno.cz> wrote:

> Code in Java:
>
>        int a = 1;
>        int b = 0;
>        long startTime = System.currentTimeMillis();
>
>        for (int i=0; i<1000; i++)
>        {
>            try {
>                try {
>                    int c = a / b;
>                } catch (Exception e1) {
>                    try {
>                        try {
>                            int c = a / b;
>                        } catch (Exception e2) { int c = a / b; }
>                    } catch (Exception e3) { }
>                }
>            } catch (Exception e4) { }
>        }
>        System.out.println(System.currentTimeMillis()-startTime);
>
> Code in Smalltalk:
>
>     | a b c |
>     a := 1.
>     b := 0.
>     [
>         1000 timesRepeat: [
>             [
>                  [
>                      c := a // b.
>                  ] on: Exception do: [
>                      [
>                          [
>                              c := a // b.
>                          ] on: Exception do: [ c := a // b ]
>                      ] on: Exception do: []
>                  ]
>             ] on: Exception do: []
>         ]
>     ] timeToRun
>
> On my notebook:
> Java: about 36 ms,
> Squeak: about 25 ms
> VisualWorks: about 12 ms
> C# (on the other machine): more than 100 ms
>
> Cheers,
> -- Pavel
>
>





More information about the Squeak-dev mailing list