Guest User

Untitled

a guest
Dec 17th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. require 'benchmark'
  2.  
  3. array = Array.new(1_000_000, { id: 'key' })
  4. values = ['.p12', '.pfx']
  5.  
  6. Benchmark.bmbm(7) do |bm|
  7. bm.report('to_h') do
  8. array.map do |prop|
  9. [
  10. prop[:id],
  11. values
  12. ]
  13. end.to_h
  14. end
  15.  
  16. bm.report('inject') do
  17. array.inject({}) do |acc, prop|
  18. acc.merge("#{prop[:id]}" => values)
  19. end
  20. end
  21. end
  22.  
  23. Rehearsal -------------------------------------------
  24. to_h 0.400000 0.020000 0.420000 ( 0.435615)
  25. inject 2.090000 0.110000 2.200000 ( 2.209907)
  26. ---------------------------------- total: 2.620000sec
  27.  
  28. user system total real
  29. to_h 0.300000 0.160000 0.460000 ( 0.449012)
  30. inject 1.980000 0.090000 2.070000 ( 2.075692)
Add Comment
Please, Sign In to add comment