Last active
August 29, 2015 14:07
-
-
Save krainboltgreene/2433adbb60c0cdcd356c 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 "benchmark/ips" | |
require "json" | |
require "oj" | |
require "yajl" | |
require "yajl/version" | |
puts "OS Name: #{`uname -a`}" | |
puts `sw_vers` | |
puts "Ruby Version: #{`ruby -v`}" | |
puts "RubyGems Version: #{`gem -v`}" | |
puts "RVM Version: #{`rvm -v`}" | |
puts "oj.gem Version: #{Oj::VERSION}" | |
puts "yajl-ruby.gem Version: #{Yajl::VERSION}" | |
BIG_LOAD = File.read("big.json") | |
BIG_DUMP = Marshal.load(File.read("big.json.rb")) | |
Benchmark.ips do |analysis| | |
analysis.time = 5 | |
analysis.warmup = 2 | |
analysis.report("stdlib big load") do | |
JSON.load(BIG_LOAD.dup) | |
end | |
analysis.report("oj big load")do | |
Oj.load(BIG_LOAD.dup) | |
end | |
analysis.report("yajl big load")do | |
Yajl::Parser.new.parse(BIG_LOAD.dup) | |
end | |
analysis.compare! | |
end | |
Benchmark.ips do |analysis| | |
analysis.time = 5 | |
analysis.warmup = 2 | |
analysis.report("stdlib big dump") do | |
JSON.dump(BIG_DUMP.dup) | |
end | |
analysis.report("oj big dump")do | |
Oj.dump(BIG_DUMP.dup) | |
end | |
analysis.report("yajl big dump")do | |
Yajl::Encoder.new.encode(BIG_DUMP.dup) | |
end | |
analysis.compare! | |
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
require "benchmark/ips" | |
require "json" | |
require "oj" | |
require "yajl" | |
require "yajl/version" | |
puts "OS Name: #{`uname -a`}" | |
puts `sw_vers` | |
puts "Ruby Version: #{`ruby -v`}" | |
puts "RubyGems Version: #{`gem -v`}" | |
puts "RVM Version: #{`rvm -v`}" | |
puts "oj.gem Version: #{Oj::VERSION}" | |
puts "yajl-ruby.gem Version: #{Yajl::VERSION}" | |
SMALL_LOAD = %|{"a":"1", "b": 2, "c": { "z": "9", "x": 10 }, "d": ["a", 1, {}, []]}| | |
SMALL_DUMP = {"a" => "1", "b" => 2, "c" => { "z" => "9", "x" => 10 }, "d" => ["a", 1, {}, []]} | |
Benchmark.ips do |analysis| | |
analysis.time = 5 | |
analysis.warmup = 2 | |
analysis.report("stdlib small load") do | |
JSON.load(SMALL_LOAD.dup) | |
end | |
analysis.report("oj small load")do | |
Oj.load(SMALL_LOAD.dup) | |
end | |
analysis.report("yajl small load")do | |
Yajl::Parser.new.parse(SMALL_LOAD.dup) | |
end | |
analysis.compare! | |
end | |
Benchmark.ips do |analysis| | |
analysis.time = 5 | |
analysis.warmup = 2 | |
analysis.report("stdlib small dump") do | |
JSON.dump(SMALL_DUMP.dup) | |
end | |
analysis.report("oj small dump")do | |
Oj.dump(SMALL_DUMP.dup) | |
end | |
analysis.report("yajl small dump")do | |
Yajl::Encoder.new.encode(SMALL_DUMP.dup) | |
end | |
analysis.compare! | |
end |
Author
krainboltgreene
commented
Oct 21, 2014
OS Name: Darwin macbookpro.local 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
ProductName: Mac OS X
ProductVersion: 10.9.5
BuildVersion: 13F34
Ruby Version: ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]
RubyGems Version: 2.2.2
RVM Version: rvm 1.25.33 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
oj.gem Version: 2.9.4
yajl-ruby.gem Version: 1.1.0
Calculating -------------------------------------
stdlib big load 20 i/100ms
oj big load 34 i/100ms
yajl big load 21 i/100ms
-------------------------------------------------
stdlib big load 194.7 (±12.8%) i/s - 960 in 5.025935s
oj big load 332.4 (±8.1%) i/s - 1666 in 5.047904s
yajl big load 218.5 (±14.2%) i/s - 1092 in 5.110287s
Comparison:
oj big load: 332.4 i/s
yajl big load: 218.5 i/s - 1.52x slower
stdlib big load: 194.7 i/s - 1.71x slower
Calculating -------------------------------------
stdlib big dump 20 i/100ms
oj big dump 79 i/100ms
yajl big dump 30 i/100ms
-------------------------------------------------
stdlib big dump 231.6 (±19.4%) i/s - 1120 in 5.042465s
oj big dump 857.6 (±17.7%) i/s - 4187 in 5.042009s
yajl big dump 409.6 (±16.4%) i/s - 2010 in 5.063403s
Comparison:
oj big dump: 857.6 i/s
yajl big dump: 409.6 i/s - 2.09x slower
stdlib big dump: 231.6 i/s - 3.70x slower
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment