Created
July 13, 2016 06:10
-
-
Save amatsuda/41b6c895d9eef2a48f6053878f969379 to your computer and use it in GitHub Desktop.
This file contains 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
require 'benchmark/ips' | |
require 'json' | |
require 'oj' | |
require 'multi_json' | |
Benchmark.ips do |x| | |
hash = 100.times.inject(Hash.new) {|h, i| h["key#{i}"] = i; h} | |
x.report('to_json') do | |
hash.to_json | |
end | |
x.report('MultiJson') do | |
MultiJson.dump hash | |
end | |
x.compare! | |
end |
This file contains 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
Warming up -------------------------------------- | |
to_json 2.206k i/100ms | |
MultiJson 9.762k i/100ms | |
Calculating ------------------------------------- | |
to_json 22.540k (± 7.0%) i/s - 112.506k in 5.017223s | |
MultiJson 102.093k (± 9.8%) i/s - 507.624k in 5.046538s | |
Comparison: | |
MultiJson: 102093.5 i/s | |
to_json: 22540.3 i/s - 4.53x slower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment