配列とハッシュの速度比較
require 'benchmark' table_a=nil table_h=nil puts '*add' n = 1000 Benchmark.bm(7) do |x| x.report("array:") do n.times do table_a = [] 10000.times do table_a << rand() end end end x.report("hash:") do n.times do table_h = {} 10000.times do table_h[rand()] = nil end end end end puts '*search' n = 10000 Benchmark.bm(7) do |x| x.report("array:") do n.times { table_a.include?(1.0) } end x.report("hash:") do n.times { table_h.key?(1.0) } end end