Can Squeak be faster than Java? Yes :-)

Pavel Krivanek squeak1 at continentalbrno.cz
Fri Feb 16 21:03:20 UTC 2007


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