require 'benchmark'
n = 1000
Benchmark.bm do |bm|
keys = (1..10000).to_a
hash = Hash[keys.zip(keys)]
bm.report do
n.times do
keys.map{|key| hash[key] }
end
end
bm.report do
n.times do
hash.values_at(*keys)
end
end
end
# ruby-2.0.0-p195
# user system total real
# 2.010000 0.060000 2.070000 ( 2.074412)
# 1.130000 0.050000 1.180000 ( 1.191744)
# jruby-1.7.4
# user system total real
# 1.680000 0.010000 1.690000 ( 1.148000)
# 0.450000 0.020000 0.470000 ( 0.410000)