You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently we have merge_bang_vs_[]= which suggests that Hash#[]= is faster and Hash#merge!() is slower.
But we dont have any suggestions for update_vs_[]= i.e., Hash#update() vs Hash#[]=.
require 'benchmark/ips'
ENUM = (1..100)
def fast
ENUM.each_with_object({}) do |e, h|
h[e] = e
end
end
def slow
ENUM.each_with_object({}) do |e, h|
h.update(e => e)
end
end
Benchmark.ips do |x|
x.report('Hash#[]=') { fast }
x.report('Hash#update') { slow }
x.compare!
end
Hash#update is an alias for Hash#merge!
Currently we have
merge_bang_vs_[]=
which suggests that Hash#[]= is faster and Hash#merge!() is slower.But we dont have any suggestions for
update_vs_[]=
i.e., Hash#update() vs Hash#[]=.Can we extend this to Hash#update()?
The text was updated successfully, but these errors were encountered: