Skip to content

Instantly share code, notes, and snippets.

@cmwright
Created May 18, 2014 14:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cmwright/17381202ec8d4bcb8a2a to your computer and use it in GitHub Desktop.
Save cmwright/17381202ec8d4bcb8a2a to your computer and use it in GitHub Desktop.
Benchmarking json vs oj with multiple oj modes
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
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