Skip to content

Instantly share code, notes, and snippets.

@sorentwo
Last active August 29, 2015 14:11
Show Gist options
  • Save sorentwo/e4627264e60e549953fd to your computer and use it in GitHub Desktop.
Save sorentwo/e4627264e60e549953fd to your computer and use it in GitHub Desktop.
Marshalling Benchmarks
Calculating -------------------------------------
oj:hash:dump 1.047k i/100ms
json:hash:dump 833.000 i/100ms
ruby:hash:dump 719.000 i/100ms
-------------------------------------------------
oj:hash:dump 10.622k (± 6.5%) i/s - 53.397k
json:hash:dump 8.478k (± 5.0%) i/s - 42.483k
ruby:hash:dump 7.376k (± 6.7%) i/s - 37.388k
Comparison:
oj:hash:dump: 10622.2 i/s
json:hash:dump: 8478.2 i/s - 1.25x slower
ruby:hash:dump: 7375.9 i/s - 1.44x slower
Calculating -------------------------------------
oj:hash:load 912.000 i/100ms
json:hash:load 775.000 i/100ms
ruby:hash:load 777.000 i/100ms
-------------------------------------------------
oj:hash:load 9.200k (± 5.8%) i/s - 46.512k
json:hash:load 7.653k (± 6.6%) i/s - 38.750k
ruby:hash:load 7.852k (± 7.7%) i/s - 39.627k
Comparison:
oj:hash:load: 9199.6 i/s
ruby:hash:load: 7852.2 i/s - 1.17x slower
json:hash:load: 7652.7 i/s - 1.20x slower
require 'bundler'
Bundler.setup
require 'benchmark/ips'
require 'json'
require 'oj'
require 'readthis'
REDIS_URL = 'redis://localhost:6379/11'
OPTIONS = { compressed: false }
readthis_oj = Readthis::Cache.new(REDIS_URL, OPTIONS.merge(marshal: Oj))
readthis_json = Readthis::Cache.new(REDIS_URL, OPTIONS.merge(marshal: JSON))
readthis_ruby = Readthis::Cache.new(REDIS_URL, OPTIONS.merge(marshal: Marshal))
HASH = ('a'..'z').each_with_object({}) { |key, memo| memo[key] = key }
Benchmark.ips do |x|
x.report('oj:hash:dump') { readthis_oj.write('oj', HASH) }
x.report('json:hash:dump') { readthis_json.write('json', HASH) }
x.report('ruby:hash:dump') { readthis_ruby.write('ruby', HASH) }
x.compare!
end
Benchmark.ips do |x|
x.report('oj:hash:load') { readthis_oj.read('oj') }
x.report('json:hash:load') { readthis_json.read('json') }
x.report('ruby:hash:load') { readthis_ruby.read('ruby') }
x.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment