Skip to content

Instantly share code, notes, and snippets.

@nictrix
Last active August 29, 2015 14:05
Show Gist options
  • Save nictrix/0958ee19bf1ecbdf81bd to your computer and use it in GitHub Desktop.
Save nictrix/0958ee19bf1ecbdf81bd to your computer and use it in GitHub Desktop.
json load vs. parse
require 'json'
require 'benchmark'
json = '{
"title": "Example Schema",
"type": "object",
"properties": {
"first-name": {
"type": "string"
},
"last-name": {
"type": "string"
},
"age": {
"description": "my description",
"type": "integer",
"minimum": 0
}
},
"required": ["first-name", "last-name"]
}'
Benchmark.bm(7) do |x|
x.report("JSON.load:") { JSON.load(json) }
x.report("JSON.parse:") { JSON.parse(json) }
end
user system total real
JSON.load : 0.000000 0.000000 0.000000 ( 0.000046)
JSON.parse: 0.000000 0.000000 0.000000 ( 0.000025)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment