Advertisement
Guest User

Oj performance?

a guest
Aug 8th, 2012
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.83 KB | None | 0 0
  1. require 'json'
  2. require 'benchmark'
  3. require 'oj'
  4. require 'yajl'
  5.  
  6. a = {'asdfg'=> 'asdfg', 'qwert'=> 'asdfatqwtrqewt', 'rewqrq'=>543252, 'reqrqwer'=>[143245,1234421]}
  7. j = a.to_json
  8.  
  9. N = (ARGV[0] || 100000).to_i
  10.  
  11. Benchmark.bmbm(6) do |x|
  12. #Benchmark.bm do |x|
  13.   x.report('json g') do N.times{|_| a['vczx'] = _; a.to_json} end
  14.   x.report('yajl g') do N.times{|_| a['vczx'] = _; Yajl.dump(a)} end
  15.   x.report('oj   g') do N.times{|_| a['vczx'] = _; Oj.dump(a)} end
  16.   x.report('ojc  g') do N.times{|_| a['vczx'] = _; Oj.dump(a, mode: :compat)} end
  17.   x.report('json p') do N.times{|_| JSON.parse(j)} end
  18.   x.report('yajl p') do N.times{|_| Yajl.load(j)} end
  19.   x.report('oj   g') do N.times{|_| Oj.load(j)} end
  20.   x.report('ojc  g') do N.times{|_| Oj.load(j, mode: :compat)} end
  21.   x.report('ojdocg') do N.times{|_| Oj::Doc.parse(j).fetch} end
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement