From: HIGAKI Masaru (=?iso-2022-jp?B?GyRCJFIkLCQtGyhCIBskQiReJDUkaxsoQg==?=) Date: 2008-10-26T21:08:32+09:00 Subject: [ruby-list:45593] Mac OS X でコンパイルした Ruby は遅い? ひがきです。 mixi の Ruby コミュニティで知ったのですが、 MacPorts でインストールした ruby は、 Mac OS X 標準の ruby よりも実行速度が遅いそうです。 私は MacPorts を使わずに 1.8.7 をソースからコンパイルして使っていますが、 確かに Mac OS X 標準の ruby 1.8.6 と比べると 5 倍近く遅いのです。 どうやら configure 時に --enable-pthread が付いていると遅いようです。 # 1.9 では --enable-pthread の影響はありません。 コンパイル時に何かヘマをやらかしているのでしょうか? 環境は以下の通りです。 Mac OS X 10.5.5 2.2GHz Intel Core 2 Duo 4GB 667MHz DDR2 SDRAM gcc version 4.0.1 (Apple Inc. build 5470) (Aspen 5470.3) 以下のスクリプトで確認しました。 -------- ここから -------- ここから -------- ここから -------- def fib(n) case when n <= 0; 0 when n == 1; 1 else fib(n-1) + fib(n-2) end end if defined? Profiler__ (1..8).map{|i| fib i} else require 'benchmark' puts Benchmark.measure{(1..32).map{|i| fib i}} end -------- ここまで -------- ここまで -------- ここまで -------- pthread ありの実行結果 $ ruby -v ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9.5.0] $ ruby fib.rb 49.030000 17.960000 66.990000 ( 67.367996) $ ruby -rprofile fib.rb % cumulative self self total time seconds seconds calls ms/call ms/call name 75.00 0.09 0.09 166 0.54 2.65 Object#fib 16.67 0.11 0.02 166 0.12 0.12 Fixnum#<= 8.33 0.12 0.01 158 0.06 0.06 Fixnum#- 0.00 0.12 0.00 133 0.00 0.00 Fixnum#== 0.00 0.12 0.00 1 0.00 120.00 Enumerable.map 0.00 0.12 0.00 1 0.00 0.00 Module#method_added 0.00 0.12 0.00 79 0.00 0.00 Fixnum#+ 0.00 0.12 0.00 1 0.00 120.00 Range#each 0.00 0.12 0.00 1 0.00 120.00 #toplevel pthread なしの実行結果 $ ruby -v ruby 1.8.7 (2008-08-11 patchlevel 72) [i686-darwin9.5.0] $ ruby fib.rb 11.520000 0.030000 11.550000 ( 11.629248) $ ruby -rprofile fib.rb % cumulative self self total time seconds seconds calls ms/call ms/call name 100.00 0.03 0.03 166 0.18 0.48 Object#fib 0.00 0.03 0.00 133 0.00 0.00 Fixnum#== 0.00 0.03 0.00 166 0.00 0.00 Fixnum#<= 0.00 0.03 0.00 1 0.00 30.00 Enumerable.map 0.00 0.03 0.00 158 0.00 0.00 Fixnum#- 0.00 0.03 0.00 1 0.00 0.00 Module#method_added 0.00 0.03 0.00 79 0.00 0.00 Fixnum#+ 0.00 0.03 0.00 1 0.00 30.00 Range#each 0.00 0.03 0.00 1 0.00 30.00 #toplevel --ひがき