Skip to content

Instantly share code, notes, and snippets.

@tmaeda
Created November 22, 2009 00:54
Show Gist options
  • Save tmaeda/240354 to your computer and use it in GitHub Desktop.
Save tmaeda/240354 to your computer and use it in GitHub Desktop.
MacRuby0.5動かしてみた。めちゃめちゃ速い。
@MacBook Core2Duo 2.2GHz/4MB二次キャッシュ/4GBメモリ/800MHzバス
tmaeda-no-macbook:tmp tmaeda$ time ruby -v fib.rb 41
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9]
165580141
real 3m18.873s
user 3m14.033s
sys 0m1.499s
tmaeda-no-macbook:tmp tmaeda$ time /usr/local/ruby-pkg/ruby19trunk/bin/ruby -v fib.rb 41
ruby 1.9.2dev (2009-11-21 trunk 25882) [i386-darwin9.8.0]
165580141
real 0m48.700s
user 0m47.555s
sys 0m0.393s
tmaeda-no-macbook:tmp tmaeda$ time macruby -v fib.rb 41
MacRuby version 0.5 (ruby 1.9.0) [universal-darwin9.0, x86_64]
165580141
real 0m5.684s
user 0m5.530s
sys 0m0.078s
tmaeda-no-macbook:tmp tmaeda$ macrubyc fib.rb -o fib_rb
tmaeda-no-macbook:tmp tmaeda$ time ./fib_rb 41
165580141
real 0m4.629s
user 0m4.496s
sys 0m0.067s
tmaeda-no-macbook:tmp tmaeda$ cat fib.rb
def fib(n)
if n < 3
return 1
else
fib(n-1) + fib(n-2)
end
end
puts fib(ARGV[0].to_i)
tmaeda-no-macbook:tmp tmaeda$ gcc -O2 fib.c -o fib_c
tmaeda-no-macbook:tmp tmaeda$ time ./fib_c 41
165580141
real 0m1.802s
user 0m1.765s
sys 0m0.012s
tmaeda-no-macbook:tmp tmaeda$ cat fib.c
#include <stdio.h>
int fib(int n)
{
if (n < 3)
return 1;
else
return fib(n-1) + fib(n-2);
}
int main(int argc, char** argv)
{
printf("%d", fib(atoi(argv[1])));
}
Maglevも動かしてみた。
tmaeda-no-macbook:MagLev-22578.MacOSX tmaeda$ time maglev-ruby ~/tmp/fib.rb 41
165580141
real 0m12.102s
user 0m10.997s
sys 0m0.188s
MacRubyの方が速かった。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment