Created
August 12, 2013 10:17
-
-
Save mashiro/6209719 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| # -*- encoding: utf-8 -*- | |
| require 'benchmark' | |
| require 'multi_json' | |
| require 'json' | |
| require 'yajl' | |
| require 'oj' | |
| N = 1000 | |
| TEST = [1, 100, 10000] | |
| ENGINES = [:json_gem, :yajl, :oj] | |
| Benchmark.bmbm do |bm| | |
| el = ENGINES.map(&:to_s).map(&:length).max | |
| tl = TEST.map(&:to_s).map(&:length).max | |
| TEST.each do |size| | |
| ENGINES.each do |t| | |
| bm.report "#{t.to_s.rjust(el)} encode array #{size.to_s.rjust(tl)}" do | |
| MultiJson.engine = t | |
| data = (1..size).to_a | |
| N.times { MultiJson.encode data } | |
| end | |
| end | |
| end | |
| TEST.each do |size| | |
| ENGINES.each do |t| | |
| bm.report "#{t.to_s.rjust(el)} encode object #{size.to_s.rjust(tl)}" do | |
| MultiJson.engine = t | |
| data = {} | |
| size.times { |n| data[n.to_s] = n.to_s } | |
| N.times { MultiJson.encode data } | |
| end | |
| end | |
| end | |
| TEST.each do |size| | |
| ENGINES.each do |t| | |
| bm.report "#{t.to_s.rjust(el)} decode array #{size.to_s.rjust(tl)}" do | |
| MultiJson.engine = t | |
| data = JSON.dump (1..size).to_a | |
| N.times { MultiJson.decode data } | |
| end | |
| end | |
| end | |
| TEST.each do |size| | |
| ENGINES.each do |t| | |
| bm.report "#{t.to_s.rjust(el)} decode object #{size.to_s.rjust(tl)}" do | |
| MultiJson.engine = t | |
| data = {} | |
| size.times { |n| data[n.to_s] = n.to_s } | |
| data = JSON.dump data | |
| N.times { MultiJson.decode data } | |
| end | |
| end | |
| end | |
| end |
Author
mashiro
commented
Aug 12, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment