Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. require 'active_support/core_ext/hash'
  2. require 'benchmark/ips'
  3. require 'json'
  4.  
  5. N = 1000
  6. M = 100
  7.  
  8. TEST_ARRAY = N.times.map do |n|
  9. h = { 'some_key' => "H #{n}" }
  10. M.times do |m|
  11. h = { h: h }
  12. end
  13. end
  14.  
  15. TEST_HASH = { array: TEST_ARRAY }
  16.  
  17. TEST_JSON = TEST_HASH.to_json
  18.  
  19. Benchmark.ips do |x|
  20. x.report("JSON.parse(symbolize_names: true)") do
  21. JSON.parse(TEST_JSON, symbolize_names: true)
  22. end
  23. x.report("JSON.parse then deep_symbolize_keys") do
  24. JSON.parse(TEST_JSON).deep_symbolize_keys
  25. end
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement