Skip to content

Instantly share code, notes, and snippets.

@mpelzsherman
Created February 13, 2016 03:36
Show Gist options
  • Save mpelzsherman/52be2bffaef676cde243 to your computer and use it in GitHub Desktop.
Save mpelzsherman/52be2bffaef676cde243 to your computer and use it in GitHub Desktop.
require 'oj'
Oj.default_options = { mode: :compat }
test_json = '{"a":"Alpha","b":true,"c":12345,"d":[true,[false,[-123456789,null],3.9676,["Something else.",false],null]],"e":{"zero":null,"one":1,"two":2,"three":[3],"four":[0,1,2,3,4]},"f":null,"h":{"a":{"b":{"c":{"d":{"e":{"f":{"g":null}}}}}}},"i":[[[[[[[null]]]]]]]}'
start_time = Time.now
1000000.times do
Oj.load(test_json)
end
end_time = Time.now
p "compat mode: #{end_time - start_time} seconds"
Oj.default_options = { mode: :object }
start_time = Time.now
1000000.times do
Oj.load(test_json)
end
end_time = Time.now
p "object mode: #{end_time - start_time} seconds"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment