やっぱり Gauche はすごい

OCaml のソースを吐けるようになったので、実行速度を比べてみることに。使ったのは次のソース。

(define (fib x)
  (if (= x 0)
      0
      (if (= x 1)
          1
          (+ (fib (- x 1)) (fib (- x 2))))))
(define main (print (fib 25)))

結果。

% ./minscheme compile f.scm
% gosh f.scm
75025
% time gosh f.scm
75025
gosh f.scm  0.21s user 0.02s system 77% cpu 0.298 total
% time ./minscheme run f.scm
75025
./minscheme run f.scm  11.27s user 0.33s system 96% cpu 12.002 total
% time ./f
75025
./f  0.29s user 0.01s system 80% cpu 0.378 total
%  

gosh 速っ!というか俺のインタプリタ遅っ!
f は、自作のコンパイラSchemeOCaml にしたあと、 ocamlopt でネイティブコンパイルしたやつです。バイトコードコンパイルのほうがいいのかな。