Skip to content

Instantly share code, notes, and snippets.

@vidmantas
Created July 11, 2013 08:43
Show Gist options
  • Save vidmantas/5973700 to your computer and use it in GitHub Desktop.
Save vidmantas/5973700 to your computer and use it in GitHub Desktop.
OJ vs YAJL
ruby oj_vs_yajl_bm.rb
user system total real
yajl parsing: 5.840000 0.010000 5.850000 ( 5.868295)
oj parsing: 1.610000 0.140000 1.750000 ( 2.056829)
yajl dump: 5.890000 0.000000 5.890000 ( 5.911014)
oj dump: 1.270000 0.000000 1.270000 ( 1.277446)
source:
require 'oj'
require 'yajl/json_gem'
require 'benchmark'
n = 1_000_000
raw_json = "{\"user\":{\"a\":1,\"b\":2,\"c\":\"3\",\"d\":521234.134,\"e\":null}}"
raw_hash = { "user" => { "a" => 1, "b" => 2, "c" => "3", "d" => 521234.134, "e" => nil } }
Benchmark.bm do |x|
x.report("yajl parsing:") do
n.times { JSON.parse(raw_json) }
end
x.report("oj parsing:") do
n.times { Oj.load(raw_json) }
end
x.report("yajl dump:") do
n.times { JSON.dump(raw_hash) }
end
x.report("oj dump:") do
n.times { Oj.dump(raw_hash) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment