Skip to content

Instantly share code, notes, and snippets.

@AaronRustad
Created April 24, 2013 19:53
Show Gist options
  • Save AaronRustad/d6f20229b9f19f6d163e to your computer and use it in GitHub Desktop.
Save AaronRustad/d6f20229b9f19f6d163e to your computer and use it in GitHub Desktop.
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 { MultiJson.load(json) }
end
x.report("yajl") do
n.times { Yajl::Parser.new.parse(json) }
end
end
object = {abc: 'def'}
Benchmark.bm(17) do |x|
x.report("multi/json") do
MultiJson.use(:json_pure)
n.times { MultiJson.dump(object) }
end
x.report("json") { n.times { JSON(json) } }
x.report("multi/oj") do
MultiJson.use(:oj)
n.times { MultiJson.dump(object) }
end
x.report("oj") { n.times { Oj.dump(json) } }
x.report("multi/yajl") do
MultiJson.use(:yajl)
n.times { MultiJson.dump(json) }
end
x.report("yajl") do
n.times { Yajl::Encoder.encode(json) }
end
end
user system total real
multi/json 0.570000 0.010000 0.580000 ( 0.591576)
json 0.170000 0.020000 0.190000 ( 0.178378)
multi/oj 0.440000 0.010000 0.450000 ( 0.456493)
oj 0.210000 0.060000 0.270000 ( 0.268035)
multi/yajl 0.530000 0.030000 0.560000 ( 0.555605)
yajl 0.190000 0.040000 0.230000 ( 0.228279)
user system total real
multi/json 0.550000 0.010000 0.560000 ( 0.562655)
json 0.190000 0.010000 0.200000 ( 0.196212)
multi/oj 0.410000 0.000000 0.410000 ( 0.411601)
oj 0.000000 0.000000 0.000000 ( 0.007718)
multi/yajl 0.520000 0.020000 0.540000 ( 0.530797)
yajl 0.180000 0.020000 0.200000 ( 0.201096)
@ceclinux
Copy link

ceclinux commented Feb 1, 2018

my benchmark on i5-8250U, running Linux ceclinux-pc 4.9.77-1-MANJARO #1 SMP PREEMPT Wed Jan 17 23:04:54 UTC 2018 x86_64 GNU/Linux

Running via Spring preloader in process 23118
                        user     system      total        real
multi/json          0.240000   0.010000   0.250000 (  0.250096)
json                0.110000   0.000000   0.110000 (  0.113757)
multi/oj            0.220000   0.000000   0.220000 (  0.216726)
oj                  0.170000   0.060000   0.230000 (  0.230328)
multi/yajl          2.060000   0.010000   2.070000 (  2.063019)
yajl                0.110000   0.010000   0.120000 (  0.124362)
                        user     system      total        real
multi/json          0.590000   0.000000   0.590000 (  0.596703)
json                0.180000   0.000000   0.180000 (  0.176591)
multi/oj            0.170000   0.000000   0.170000 (  0.168770)
oj                  0.010000   0.010000   0.020000 (  0.008189)
multi/yajl          0.180000   0.000000   0.180000 (  0.186003)
yajl                0.100000   0.000000   0.100000 (  0.095512)

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