Created
May 18, 2014 14:50
-
-
Save cmwright/17381202ec8d4bcb8a2a to your computer and use it in GitHub Desktop.
Benchmarking json vs oj with multiple oj modes
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 'json' | |
require 'oj' | |
require 'benchmark' | |
require 'securerandom' | |
h = {} | |
10_000.times{|i| h[SecureRandom.uuid] = i} | |
Benchmark.bmbm do |x| | |
x.report("json") { 1000.times{ n = h.to_json} } | |
x.report("oj default") { 1000.times{ n = Oj.dump(h)} } | |
x.report("oj compat") { 1000.times{ n = Oj.dump(h, mode: :compat)} } | |
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
Rehearsal ---------------------------------------------- | |
json 13.990000 0.250000 14.240000 ( 14.257051) | |
oj default 3.260000 0.230000 3.490000 ( 3.491028) | |
oj compat 3.360000 0.240000 3.600000 ( 3.593109) | |
------------------------------------ total: 21.330000sec | |
user system total real | |
json 13.740000 0.240000 13.980000 ( 13.992641) | |
oj default 3.020000 0.230000 3.250000 ( 3.248077) | |
oj compat 3.060000 0.230000 3.290000 ( 3.286443) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment