Created
April 24, 2013 19:11
-
-
Save darrenboyd/5454727 to your computer and use it in GitHub Desktop.
JSON Parser speed test.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
gem 'multi_json' | |
gem 'json' | |
gem 'oj' | |
gem 'yajl-ruby' | |
require 'benchmark' | |
require 'multi_json' | |
require 'json' | |
require 'oj' | |
require 'yajl' | |
json = '{"abc":"def"}' | |
n = 50000 | |
Benchmark.bm(17) do |x| | |
x.report("multi/json") do | |
MultiJson.use(:json_pure) | |
n.times { MultiJson.load(json) } | |
end | |
x.report("json") { n.times { JSON::parse(json) } } | |
x.report("multi/oj") do | |
MultiJson.use(:oj) | |
n.times { MultiJson.load(json) } | |
end | |
x.report("oj") { n.times { Oj::Doc.parse(json) } } | |
x.report("multi/yajl") do | |
MultiJson.use(:yajl) | |
n.times { Yajl::Parser.new.parse(json) } | |
end | |
x.report("yajl") do | |
n.times { Yajl::Parser.new.parse(json) } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby perf.rb | |
user system total real | |
multi/json 1.270000 0.030000 1.300000 ( 1.309317) | |
json 0.380000 0.020000 0.400000 ( 0.417638) | |
multi/oj 1.000000 0.040000 1.040000 ( 1.044163) | |
oj 0.500000 0.140000 0.640000 ( 0.647286) | |
multi/yajl 0.360000 0.080000 0.440000 ( 0.454949) | |
yajl 0.290000 0.030000 0.320000 ( 0.324051) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment