Created
June 12, 2014 07:42
-
-
Save banyan/f5b3e34200adeef57b5c to your computer and use it in GitHub Desktop.
oj benchmark
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
source 'https://rubygems.org' | |
gem 'multi_json' | |
gem 'yajl-ruby' | |
gem 'json' | |
gem 'oj' |
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
# script comes from here: https://github.com/ohler55/oj/issues/78 | |
require 'multi_json' | |
require 'benchmark' | |
require 'yajl' | |
require 'json' | |
require 'oj' | |
iter = 1_000_000 | |
puts "Benchmarks for different JSON handlers with MultiJson." | |
puts " Ruby #{RUBY_VERSION}" | |
puts " #{iter} iterations" | |
MultiJson.engine = :oj | |
dt = Benchmark.realtime { iter.times { MultiJson.decode(%({"k1":"val1","k2":"val2","k3":"val3"})) }} | |
et = Benchmark.realtime { iter.times { MultiJson.encode(k1: "val1", k2: "val2", k3: "val3") }} | |
puts " Oj decode: #{dt} encode: #{et}" | |
MultiJson.engine = :yajl | |
dt = Benchmark.realtime { iter.times { MultiJson.decode(%({"k1":"val1","k2":"val2","k3":"val3"})) }} | |
et = Benchmark.realtime { iter.times { MultiJson.encode(k1: "val1", k2: "val2", k3: "val3") }} | |
puts " Yajl decode: #{dt} encode: #{et}" | |
MultiJson.engine = :json_gem | |
dt = Benchmark.realtime { iter.times { MultiJson.decode(%({"k1":"val1","k2":"val2","k3":"val3"})) }} | |
et = Benchmark.realtime { iter.times { MultiJson.encode(k1: "val1", k2: "val2", k3: "val3") }} | |
puts " Json decode: #{dt} encode: #{et}" | |
Oj.default_options = { :mode => :compat, :time_format => :ruby } | |
dt = Benchmark.realtime { iter.times { Oj.load(%({"k1":"val1","k2":"val2","k3":"val3"})) }} | |
et = Benchmark.realtime { iter.times { Oj.dump(k1: "val1", k2: "val2", k3: "val3") }} | |
puts "Raw Oj decode: #{dt} encode: #{et}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment