-
-
Save AaronRustad/d6f20229b9f19f6d163e to your computer and use it in GitHub Desktop.
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 { 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 |
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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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