[Prev][Next][Index][Thread]

Re: Fun-O Basic Edition Compiler



Scott McKay wrote:
> 
> Could you post the exact code you used for Dylan, Lisp, and Java?
> You might not be comparing apples to apples...

Code for all three is below. The Lisp code I typed into the
listener and then did (compile 'tak) and (compile 'test-tak) and
ran it with (time (test-tak 2000)).

The Dylan code uses the "timing" macro and is run along with other
Gabriel benchmarks.

The Java code just uses currentTimeMillis() as you can see.
Without HotSpot it takes about three times as long as the Dylan
code, but nobody runs without HotSpot these days.

I'm getting slightly better timings for all three today (not sure
why) but the relative times are about the same.  I'm on a P3/650
with win2k.

FunDev        Lispworks     Java       Java
Prod Mode                              static[1]
---------------------------------------------
11.314s       6.8s          4.297s     3.795s
1.0           1.7x          2.6x       3.0x


define method tak (x :: <integer>, y :: <integer>, z :: <integer>)
  if (y >= x)
    z
  else
    tak(tak(x - 1, y, z),
        tak(y - 1, z, x),
        tak(z - 1, x, y))
  end if
end;

define function testtak ()
  for (i from 1 to 2000)
    tak(18, 12, 6);
  end;
end;

(defun tak (x y z)
  (if (>= y x)
      z
    (tak (tak (- x 1) y z)
         (tak (- y 1) z x)
         (tak (- z 1) x y))))

(defun test-tak (n)
  (dotimes (i n)
    (tak 18 12 6)))

public class Tak {
    // [1] make this method static
    public int tak (int x, int y, int z) {
        if (y >= x)
            return z;
        else
            return tak(tak(x - 1, y, z),
                       tak(y - 1, z, x),
                       tak(z - 1, x, y));
    }

    public static void main (String[] args) {
        Tak t = new Tak();
        long start = System.currentTimeMillis();
        for (int i = 0; i < 2000; i++) {
            // [1] call static method
            t.tak(18, 12, 6);
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }
}



Follow-Ups: References: