Benchmark ! require ‘bmark’ # https://gist.github.com/sunny/c47982974f749da82b6f require ‘active_support/core_ext/enumerable’ hash = {} 100.times do |i| hash[i] = { min: 5, max: 10 } end bmark 200_000, each_inject: each_map_reduce: each_sum: inject: inject_block_var: sum_block_var: values_inject: values_map_reduce: values_sum:
-> -> -> -> -> -> -> -> ->
{ { { { { { { { {
hash.each_value.inject(0) hash.each_value.map hash.each_value.sum hash.inject(0) hash.inject(0) hash.sum hash.values.inject(0) hash.values.map hash.values.sum
{ { { { { { { { {
|i, |h| |v| |i, |i, |, |i, |h| |v|
h| i + h[:min] } }, h[:min] }.reduce(:+) }, v[:min] } }, h| i + h[1][:min] } }, (, v)| i + v[:min] } }, v| v[:min] } }, h| i + h[:min] } }, h[:min] }.reduce(:+) }, v[:min] } }