Skip to content

Instantly share code, notes, and snippets.

@krainboltgreene
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krainboltgreene/2433adbb60c0cdcd356c to your computer and use it in GitHub Desktop.
Save krainboltgreene/2433adbb60c0cdcd356c to your computer and use it in GitHub Desktop.
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
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
@krainboltgreene
Copy link
Author

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 small load      6117 i/100ms
       oj small load     13145 i/100ms
     yajl small load      6246 i/100ms
-------------------------------------------------
   stdlib small load    60677.1 (±21.1%) i/s -     281382 in   5.025119s
       oj small load   178474.9 (±7.4%) i/s -     893860 in   5.035986s
     yajl small load   100052.5 (±10.6%) i/s -     499680 in   5.057387s

Comparison:
       oj small load:   178474.9 i/s
     yajl small load:   100052.5 i/s - 1.78x slower
   stdlib small load:    60677.1 i/s - 2.94x slower

Calculating -------------------------------------
   stdlib small dump      7350 i/100ms
       oj small dump     18115 i/100ms
     yajl small dump     10314 i/100ms
-------------------------------------------------
   stdlib small dump    76106.0 (±14.8%) i/s -     374850 in   5.062636s
       oj small dump   289944.7 (±10.8%) i/s -    1431085 in   5.002248s
     yajl small dump   139930.4 (±7.7%) i/s -     701352 in   5.044359s

Comparison:
       oj small dump:   289944.7 i/s
     yajl small dump:   139930.4 i/s - 2.07x slower
   stdlib small dump:    76106.0 i/s - 3.81x slower

@krainboltgreene
Copy link
Author

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