Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
18 lines (13 sloc) 257 Bytes
require "benchmark/ips"
HASH = Hash[*("a".."z").to_a.shuffle]
def fast
HASH.sort_by { |k, _v| k }.to_h
end
def slow
HASH.sort.to_h
end
Benchmark.ips do |x|
x.report("sort_by + to_h") { fast }
x.report("sort + to_h") { slow }
x.compare!
end
You can’t perform that action at this time.