再び MagLev と Matz Ruby (Ruby1.8)、YARV(Ruby1.9)を戦わせてみる

MagLev 1.0.0 リリース記念。

MagLev is a fast, stable, 64-bit open source implementation of the Ruby programming language and libraries built on top of VMware’s GemStone/S 3.1 Virtual Machine.

The MagLev VM takes full advantage of GemStone/S JIT to native code performance, distributed shared cache, fully ACID transactions, and enterprise class NoSQL data management capabilities to provide a robust and durable programming platform. It can transparently manage a much larger amount (terabytes) of data and code than will fit in memory. There are no restrictions on what types of objects, classes, blocks, threads or continuations that can be stored and executed.

MagLev 1.0.0 was released on October 31, 2011.

MagLev


恒例のフィボナッチベンチです。以前のとそんなに変わり映えしませんが―、ただマシンは Core 2 Duo 2.4GHz から Core i7 1.8Ghz に変っています。


MagLev が 64-bit環境のみ(あいにく手元の Win 7 環境は 32 bit)なので VMware 仮想マシンDebian squeeze amd64)上で計測しています。

 言語        処理系                 速度[秒]  
 Ruby  Ruby1.8.7  90.0
 Ruby  Ruby1.9.3  18.6
 Ruby  Rubinius2.0.0dev  19.8
 Ruby  MagLev1.0.0   5.04
 Python  Python3.1.3  32.4
 Scheme  Gauche0.9  11.3
 JavaScript  Node.js-v0.6.1-pre   1.81


以下は同じマシンの Win 7 32-bit版(Smalltalk 以外は Cygwin)での参考値。

 言語        処理系                 速度[秒]  
 Ruby  Ruby1.8.7  91.9
 Ruby  Ruby1.9.3  18.8
 Python  Python3.1.2  38.8
 Scheme  Gauche0.9  10.8
 Smalltalk  Squeak4.1 (ノーマルVM)  10.9
 Smalltalk  Squeak4.1 (Cog VM)   1.35
 Smalltalk  VisualWorks7.7   0.967
 JavaScript  Node.js-0.4.1   2.54
Ruby
$ ruby1.8 -v fib.rb 39
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
63245986
90.070454 sec
$ ruby -v fib.rb 39
ruby 1.9.3p0 (2011-10-30 revision 33569) [x86_64-linux]
63245986
18.556996909 sec
$ ruby -v fib.rb 39
rubinius 2.0.0dev (1.8.7 4ef646f8 yyyy-mm-dd JI) [x86_64-unknown-linux-gnu]
63245986
19.788842 sec
$ maglev start
startstone[Info]: Starting Stone repository monitor 'maglev'.
startstone[Info]: GemStone server 'maglev' has been started.

$ maglev-ruby -v fib.rb 39
maglev 1.0.0 (ruby 1.8.7) (2011-10-31 rev 1.0.0-27184)[Linux x86_64]
63245986
5.039022 sec
$ cat fib.rb
def fib(n)
  return n if n < 2
  fib(n-2) + fib(n-1)
end

n = ARGV[0].to_i
start = Time.now
puts fib(n), (Time.now - start).to_s + " sec"
$ ruby -v fib.rb 39
ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-cygwin]
63245986
91.865 sec
$ ruby -v fib.rb 39
ruby 1.9.3p0 (2011-10-30 revision 33569) [i386-cygwin]
63245986
18.769 sec
Python
$ python3 -V; python3 fib.py 39
Python 3.1.3
63245986
32.3685669899 sec
$ cat fib.py
from sys import argv
from time import time

def fib(n):
  if n < 2:
    return n
  else:
    return fib(n-2) + fib(n-1)

n = int(argv[1])
start = time()
print(fib(n))
print(str(time() - start) + " sec")
$ python3 -V; python fib.py 39
Python 3.1.2
63245986
38.7690000534 sec
Scheme
$ gosh -V; gosh fib.scm 39
Gauche scheme shell, version 0.9 [utf-8,pthreads], x86_64-pc-linux-gnu
;(time (fib (string->number (car *argv*))))
; real  11.341
; user  11.310
; sys    0.000
$ cat fib.scm
(define (fib n) (if (< n 2) n (+ (fib (- n 2)) (fib (- n 1)))))
(display (time (fib (string->number (car *argv*)))))
$ gosh -V; gosh fib.scm 39
Gauche scheme shell, version 0.9 [utf-8,pthreads], i686-pc-cygwin
;(time (fib (string->number (car *argv*))))
; real  10.850
; user  10.827
; sys    0.000
63245986
JavaScript
$ node -v; node fib39.js
v0.6.1-pre
63245986
1814 msec
$ cat fib39.js
function fib(n) {
  if (n < 2) {
    return n;
  } else {
    return fib(n-2) + fib(n-1);
  }
}

var start = new Date();
console.log(fib(39));
console.log(new Date() - start + " msec");
$ node -v; node fib39.js
v0.4.1
63245986
2543 msec
Smalltalk
| fib39 |
Integer compile: 'fib
  ^(self < 2) ifTrue: [self] ifFalse: [(self - 2) fib + (self - 1) fib]'.

(Time millisecondsToRun: [fib39 := 39 fib]) -> fib39

"Squeak4.2 (Cog VM)    => 1354 -> 63245986 "
"Squeak4.2 (normal VM) => 10886 -> 63245986 "
"VisualWorks7.7nc      => 967 -> 63245986) "