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|
- #Benchmark.bm do |x|
- x.report('json g') do N.times{|_| a['vczx'] = _; a.to_json} end
- x.report('yajl g') do N.times{|_| a['vczx'] = _; Yajl.dump(a)} end
- x.report('oj g') do N.times{|_| a['vczx'] = _; Oj.dump(a)} end
- x.report('ojc g') do N.times{|_| a['vczx'] = _; 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
- x.report('ojdocg') do N.times{|_| Oj::Doc.parse(j).fetch} end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement