Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'benchmark'
- array = Array.new(1_000_000, { id: 'key' })
- values = ['.p12', '.pfx']
- Benchmark.bmbm(7) do |bm|
- bm.report('to_h') do
- array.map do |prop|
- [
- prop[:id],
- values
- ]
- end.to_h
- end
- bm.report('inject') do
- array.inject({}) do |acc, prop|
- acc.merge("#{prop[:id]}" => values)
- end
- end
- end
- Rehearsal -------------------------------------------
- to_h 0.400000 0.020000 0.420000 ( 0.435615)
- inject 2.090000 0.110000 2.200000 ( 2.209907)
- ---------------------------------- total: 2.620000sec
- user system total real
- to_h 0.300000 0.160000 0.460000 ( 0.449012)
- inject 1.980000 0.090000 2.070000 ( 2.075692)
Add Comment
Please, Sign In to add comment