Skip to content

Instantly share code, notes, and snippets.

@cnosuke
Created October 18, 2013 01:09
Show Gist options
  • Save cnosuke/7034940 to your computer and use it in GitHub Desktop.
Save cnosuke/7034940 to your computer and use it in GitHub Desktop.
require 'benchmark'
require 'msgpack'
require 'redis'
require 'json'
r = Redis.new
h = { a: 'hoge', b: 100, c: true }
n = 50000
r.flushdb
Benchmark.bm do |x|
x.report('json set: ') do
n.times { |i| r.set i, h.to_json }
end
x.report('json get: ') do
n.times { |i| JSON.parse(r.get(i)) }
end
r.flushdb
x.report('msgpack set: ') do
n.times { |i| r.set i, h.to_msgpack }
end
x.report('msgpack get: ') do
n.times { |i| MessagePack.unpack(r.get(i)) }
end
end
# RESULT
# user system total real
# json set: 3.290000 1.080000 4.370000 ( 5.120954)
# json get: 3.410000 1.060000 4.470000 ( 5.231562)
# msgpack set: 2.930000 1.050000 3.980000 ( 4.737009)
# msgpack get: 3.020000 1.040000 4.060000 ( 4.771550)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment