Ruby1.9
を入れました。
今回から YARV が入ってかなり高速になっているらしいです。
さっそく、リバーシ(オセロ)を試してみました。
def test() start = Time.now player_b = MinMaxPlayer.new(:black, 3) player_w = MinMaxPlayer2.new(:white, 3) play(player_b, player_w) p "#{(Time.now-start)} sec" end
800.406 sec Ver 1.8.6
590.844 sec Ver 1.9.0
およそ 1.36倍になりました。
確かに速くなっているけれど、ビミョーです。
別のサンプルで試してみました。
# 両替 1$,5$,10$,25$,50$ def countChange(coins, amount) cc(coins, amount, 0) end def cc(coins, amount, kindsOfCoins) if amount == 0 then 1 elsif (amount < 0) 0 elsif kindsOfCoins >= coins.length then 0 else cc(coins, amount, kindsOfCoins + 1) + cc(coins, amount - coins[kindsOfCoins], kindsOfCoins) end end COINS_JP = [500,100,50,10,5,1] COINS_US = [50,25,10,5,1] def bm start = Time.now puts countChange(COINS_JP, 500) # 19162 時間が結構かかる。 # puts countChange(COINS_JP, 1000) # 248908 かかりすぎる p "#{(Time.now-start)} sec" end
500円の両替の場合は5.78倍。
22.313 sec Ver 1.8.6
3.859 sec Ver 1.9.0
1000円の両替の場合は6.96倍。
624.406 sec Ver 1.8.6
89.672 sec Ver 1.9.0
すげー!メッチャクチャ速い!!!