Skip to content

Instantly share code, notes, and snippets.

@mtkd
Created March 4, 2012 21:16
Show Gist options
  • Save mtkd/1974822 to your computer and use it in GitHub Desktop.
Save mtkd/1974822 to your computer and use it in GitHub Desktop.
JSON parsing benchmarks
require 'benchmark'
require 'json'
require 'yajl'
data = ''
f = File.open("test.json", "r")
f.each_line do |line|
data += line
end
Benchmark.bm do |x|
x.report { 10000.times do; h = JSON.parse(data); end; }
x.report { 10000.times do; h = Yajl::Parser.new.parse(data); end; }
end
# user system total real
# JSON 2.760000 0.000000 2.760000 ( 2.763451)
# Yajl 2.090000 0.000000 2.090000 ( 2.084567)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment