Ruby Enterprise のGCの評価(その1)
AutorNariさんのRuby Enterpriseの解説(http://d.hatena.ne.jp/authorNari/20080625/1214315712)について、速くなるかも知れないですよとコメントしてしまいましたが、本当かどうかちょっと試してみました。
時間が無いので後でと書いたのですが、ぜひやらねばと思いちょっと試してみました。
その理由はkeita_yamaguchiさんが、http://d.hatena.ne.jp/keita_yamaguchi/20080623/1214163466で、
私が Rails じゃない普通のプログラムで試した時には大抵遅くなってて (でもなんか極端な場合の時だけ噂通り30%程度速かったような気がしたのですが、 その時のコード捨てちゃいました!なんてこった!)
っておっしゃっているのでちょっと不安になったってのもありますし、今日の仕事(漏水探査(水道屋なんです))が、思いのほか早く終わったってのもあります。
Ruby Enterpriseは私の使っているCygwinではうまくコンパイルできないです。通常はRuby Enterpriseの展開したルートでinstallスクリプトを実行するといいのですが、そうするとコンパイルに失敗します。どうも、独自のmallocの実装に置き換えをするみたいで、その中のmmap関連と思われる処理でこけているみたいです。sourceディレクトリにもぐって.configure/makeでコンパイルできました。実はmissing/strftime.cでちょっと躓いたのですが、適当にプログラムを修正して強引にコンパイルを通しました。
そういうことで、私の結果は怪しさが爆発しています。
評価は、Cレベルでプロファイルを取るという方法を取りました。とりあえず、ワンパターンのminilight(http://www.hxa7241.org/minilight/minilight.html)でcornel boxを実行してみました。
その結果です。実行時間が0.5%以上を占める関数だけ載せました。
Ruby 1.8.7-p22 Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 36.09 105.46 105.46 58935661 0.00 0.00 rb_eval 14.09 146.65 41.19 694378517 0.00 0.00 rb_call0 8.68 172.01 25.36 368939153 0.00 0.00 st_lookup 6.80 191.89 19.88 694378517 0.00 0.00 rb_call 3.56 202.29 10.40 342491732 0.00 0.00 rb_newobj 2.58 209.82 7.53 17281 0.00 0.00 garbage_collect 2.23 216.35 6.53 65939659 0.00 0.00 gc_mark_children 2.21 222.81 6.46 387013407 0.00 0.00 gc_mark 1.97 228.58 5.77 23383428 0.00 0.00 st_foreach 1.88 234.07 5.49 34562 0.00 0.00 mark_locations_array 1.22 237.64 3.57 80813989 0.00 0.00 ruby_xmalloc 1.20 241.14 3.50 49617907 0.00 0.00 st_insert 1.04 244.17 3.03 227452457 0.00 0.00 ivar_get 1.01 247.12 2.95 113960271 0.00 0.00 flo_mul 0.83 249.54 2.42 11663505 0.00 0.00 st_free_table 0.82 251.95 2.41 221129697 0.00 0.00 rb_float_new 0.78 254.24 2.29 _alloca 0.77 256.48 2.24 10825332 0.00 0.00 rb_yield_0 0.75 258.67 2.19 418549438 0.00 0.00 numhash 0.73 260.80 2.13 29953830 0.00 0.00 rb_obj_is_kind_of 0.67 262.75 1.95 49615609 0.00 0.00 rb_ivar_set 0.59 264.46 1.71 77749183 0.00 0.00 rb_ary_aref
ruby enterprise 1.8.6-20080624 Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 35.37 108.65 108.65 58983631 0.00 0.00 rb_eval 13.58 150.37 41.72 694973969 0.00 0.00 rb_call0 7.63 173.80 23.43 369355998 0.00 0.00 st_lookup 6.62 194.15 20.35 694973969 0.00 0.00 rb_call 3.30 204.28 10.13 342804836 0.00 0.00 rb_newobj 2.61 212.30 8.02 17058 0.00 0.00 garbage_collect 2.58 220.24 7.94 376348309 0.00 0.00 gc_mark 2.11 226.72 6.48 63034544 0.00 0.00 gc_mark_children 1.87 232.45 5.73 22827149 0.00 0.00 st_foreach 1.80 237.98 5.53 34116 0.00 0.00 mark_locations_array 1.32 242.03 4.05 477640115 0.00 0.00 rb_fast_mark_table_heap_contains 1.16 245.59 3.56 49664783 0.00 0.00 st_insert 1.10 248.97 3.38 80897170 0.00 0.00 ruby_xmalloc 1.09 252.31 3.34 114062712 0.00 0.00 flo_mul 1.04 255.51 3.20 227640499 0.00 0.00 ivar_get 0.95 258.43 2.92 29981162 0.00 0.00 rb_obj_is_kind_of 0.86 261.07 2.64 10841141 0.00 0.00 rb_yield_0 0.81 263.56 2.49 11674740 0.00 0.00 st_free_table 0.77 265.94 2.38 221321057 0.00 0.00 rb_float_new 0.76 268.28 2.34 __chkstk 0.74 270.54 2.26 419013408 0.00 0.00 numhash 0.71 272.71 2.17 432881264 0.00 0.00 rb_fast_mark_table_contains 0.60 274.55 1.84 49662584 0.00 0.00 rb_ivar_set 0.51 276.12 1.57 77817140 0.00 0.00 rb_ary_aref
続く