Skip to content

Instantly share code, notes, and snippets.

@amatsuda
Created July 13, 2016 06:10
Show Gist options
  • Save amatsuda/41b6c895d9eef2a48f6053878f969379 to your computer and use it in GitHub Desktop.
Save amatsuda/41b6c895d9eef2a48f6053878f969379 to your computer and use it in GitHub Desktop.
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
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