Skip to content

Instantly share code, notes, and snippets.

@rafbm
Created May 22, 2013 20:12
Show Gist options
  • Save rafbm/5630528 to your computer and use it in GitHub Desktop.
Save rafbm/5630528 to your computer and use it in GitHub Desktop.
Benchmarking Ruby’s JSON.load and JSON.parse.
require 'benchmark'
require 'json'
str = '{"foo": "bar"}'
Benchmark.benchmark Benchmark::CAPTION, 11 do |bm|
bm.report 'JSON.load' do
500_000.times { JSON.load(str) }
end
bm.report 'JSON.parse' do
500_000.times { JSON.parse(str) }
end
end
__END__
user system total real
JSON.load 4.840000 0.130000 4.970000 ( 4.986769)
JSON.parse 2.410000 0.020000 2.430000 ( 2.428971)
Yay JSON.parse!
@remi
Copy link

remi commented May 22, 2013

Did you try with other parsers? Like oj or yajl-ruby?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment