From: "ko1 (Koichi Sasada)" Date: 2013-08-09T19:34:13+09:00 Subject: [ruby-core:56476] [ruby-trunk - Feature #8707] Hash#reverse_each Issue #8707 has been updated by ko1 (Koichi Sasada). Assignee set to matz (Yukihiro Matsumoto) ---------------------------------------- Feature #8707: Hash#reverse_each https://bugs.ruby-lang.org/issues/8707#change-41024 Author: Glass_saga (Masaki Matsushita) Status: Feedback Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: core Target version: current: 2.1.0 Currently, {}.reverse_each calls Enumerable#reverse_each. It will make array and its size can be large. I made Hash#reverse_each to avoid array creation and performance improvement. benchmark: require "benchmark" Size = 10000 HASH = Hash[*Array.new(Size) {|i| [i, true] }.flatten] Benchmark.bmbm do |x| x.report("Hash#reverse_each") do 300.times do HASH.reverse_each {|a, b|} end end end result: trunk(r42256): Rehearsal ----------------------------------------------------- Hash#reverse_each 1.210000 0.000000 1.210000 ( 1.207964) -------------------------------------------- total: 1.210000sec user system total real Hash#reverse_each 0.950000 0.000000 0.950000 ( 0.951069) proposal: Rehearsal ----------------------------------------------------- Hash#reverse_each 0.600000 0.000000 0.600000 ( 0.600242) -------------------------------------------- total: 0.600000sec user system total real Hash#reverse_each 0.450000 0.000000 0.450000 ( 0.459006) -- http://bugs.ruby-lang.org/