æä¾ã®ãã£ãããããã³ã㧠V8 㨠SmalltalkãRubyãPythonãScheme ã¨ãæ¦ããã¦ã¿ã
爆速で話題の Google Chrome 搭載 JavaScript VM “V8” は、Animorphic Smalltalk VM がベースになっているらしい ã®ç¶ãã
ãã®éãã¨è¨ããã V8ãå®éãã©ã®ãããã®é度ã§åãã®ããå ·ä½çãªæ°å¤ã¨ãã¦è¦ã¦ã¿ãããªã£ãã®ã§ãæ軽ã«è©¦ããã¨ãã§ãããã£ãããããã³ãã§ããã®ã¹ã³ã¢ãæå ã®å¦çç³»ãã¡ã¨ä¸¦ã¹ã¦æ¯è¼ãã¦ã¿ã¾ããã
ç°å¢ã¯ Modbook 2.4GHz Core 2 Duoï¼MacBook ç¸å½ï¼ã® Vista SP1 ã§ã40çªç®ã®ãã£ããããæ°ï¼63245986ï¼ã®ç®åºã«ããã£ãç§æ°ãã«ã¦ã³ããã¦ãã¾ããçµæã¯æ¬¡ã®ããã«ãªãã¾ããã
è¨èª | å¦çç³» | ã¹ã³ã¢ [ç§]ã |
JavaScriptã | Google Chrome (V8)ã | 2.95 |
JavaScriptã | Firefox 3.01 (SpiderMonkey)ã | 31.9 |
Smalltalkã | Squeak Smalltalk 3.9ã | 14.8 |
Smalltalkã | Strongtalk 2.0ã | 1.96 |
Smalltalkã | Cincom Smalltalk (VisualWorks) 7.5ã | 1.62 |
Rubyã | Ruby 1.8ã | 106 |
Rubyã | Ruby 1.9ã | 18.2 |
Pythonã | Python 2.5ã | 52.7 |
Schemeã | Gauche 0.8ã | 17.5 |
ãã®ãã³ãã«éãã° V8 ã¯ãå
ã«ãªã£ã Strongtalk ãåç¨ Smalltalk ã«ã¯ä¸æ©åã°ãªããã®ã®ãããã§ããããç¥ããã LL è¨èªãã¡ããã¯ãã£ã¨é«éã«åä½ããããã«è¦ãã¾ããããªã©ããªãã§ããã
使ç¨ããã¹ã¯ãªããã¨åºåçµæã¯ä»¥ä¸ã«ã
â¼ JavaScriptï¼ChromeãFirefox å ±éã使ç¨æã¯ãå ¨è§ï¼ãåè§ã«ï¼
<script type="text/javascript"><ï¼-- fib = function(n) { if (n < 2) { return n; } else { return fib(n-2) + fib(n-1); } } n = 39; start = new Date(); res = fib(n); document.write(res, ", ", new Date() - start, " msec"); // --></script>
63245986, 2949 msec // Chrome 63245986, 31936 msec // Firefox
â¼ Smalltalkï¼SqueakãStrongtalkãVisualWorks å ±éï¼
Integer >> fib self < 2 ifTrue: [^self]. ^(self-2) fib + (self-1) fib
39 fib "=> 63245986 "
Time millisecondsToRun: [39 fib] "Squeak => 14797 " "Strongtalk => 1958 " "VisualWorks => 1623 "
â¼Ruby
$ cat fib.rb class Integer def fib return self if self < 2 (self-2).fib + (self-1).fib end end n = ARGV[0].to_i start = Time.now res = n.fib puts res, (Time.now - start).to_s + " sec"
$ ruby -v fib.rb 39 ruby 1.8.6 (2008-03-03 patchlevel 114) [i386-cygwin] 63245986 105.543 sec $ ruby1.9 -v fib.rb 39 ruby 1.9.0 (2008-06-19 revision 17423) [i386-cygwin] 63245986 18.163 sec
â¼Python
$ cat fib.py import sys import time def fib(n): if n < 2: return n else: return fib(n-2) + fib(n-1) n = int(sys.argv[1]) start = time.time() res = fib(n) print (res, time.time() - start)
$ python -V Python 2.5.1
$ python fib.py 39 (63245986, 52.66700005531311)
â¼Gauche
$ cat fib.scm (use srfi-19) (define (fib n) (if (< n 2) n (+ (fib (- n 2)) (fib (- n 1))))) (let* ((n (string->number (list-ref *argv* 0))) (start (current-time)) (res (fib n))) (display (list res (time-difference (current-time) start))))
$ gosh -V Gauche scheme interpreter, version 0.8.13 [utf-8,pthreads]
$ gosh fib.scm 39 (63245986 #<time-duration 17.474000000>)