Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'json'
- require 'benchmark'
- require 'oj'
- require 'yajl'
- a = {'asdfg'=> 'asdfg', 'qwert'=> 'asdfatqwtrqewt', 'rewqrq'=>543252, 'reqrqwer'=>[143245,1234421]}
- j = a.to_json
- N = (ARGV[0] || 100000).to_i
- Benchmark.bmbm(6) do |x|
- x.report('json g') do N.times{a.to_json } end
- x.report('yajl g') do N.times{Yajl.dump(a)} end
- x.report('oj g') do N.times{Oj.dump(a)} end
- x.report('ojc g') do N.times{Oj.dump(a, mode: :compat)} end
- x.report('json p') do N.times{JSON.parse(j)} end
- x.report('yajl p') do N.times{Yajl.load(j)} end
- x.report('oj g') do N.times{Oj.load(j)} end
- x.report('ojc g') do N.times{Oj.load(j, mode: :compat)} end
- # Correct use of Oj::Doc
- x.report('ojdocg') do N.times{Oj::Doc.open(j) { |x| x.fetch('asdfg') } } end
- end
- # results from ruby 1.9.3-p194 on OS X
- user system total real
- json g 0.700000 0.010000 0.710000 ( 0.706307)
- yajl g 0.660000 0.000000 0.660000 ( 0.658921)
- oj g 0.490000 0.000000 0.490000 ( 0.487269)
- ojc g 0.570000 0.000000 0.570000 ( 0.571865)
- json p 0.850000 0.000000 0.850000 ( 0.851527)
- yajl p 0.750000 0.000000 0.750000 ( 0.744586)
- oj g 0.350000 0.000000 0.350000 ( 0.351567)
- ojc g 0.450000 0.000000 0.450000 ( 0.447477)
- ojdocg 0.110000 0.000000 0.110000 ( 0.114286)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement