Skip to content

Instantly share code, notes, and snippets.

@yonkeltron
Last active December 28, 2015 17:39
Show Gist options
  • Save yonkeltron/7537277 to your computer and use it in GitHub Desktop.
Save yonkeltron/7537277 to your computer and use it in GitHub Desktop.
n = 50000
Rehearsal ----------------------------------------------
vanilla 2.980000 0.940000 3.920000 ( 4.703619)
pipelined 0.820000 0.160000 0.980000 ( 0.976310)
hmapped 0.160000 0.000000 0.160000 ( 0.228029)
------------------------------------- total: 5.060000sec
user system total real
vanilla 3.000000 0.940000 3.940000 ( 4.718813)
pipelined 0.800000 0.140000 0.940000 ( 0.945136)
hmapped 0.110000 0.000000 0.110000 ( 0.172675)
require 'redis'
require 'benchmark'
require 'securerandom'
require 'uuid'
n = 50_000
REDIS = Redis.new
KEY = 'BENCHMARK'
puts "n = #{n}"
uuids = (1..n).to_a.map { UUID.generate }
bytes = (1..n).to_a.map { SecureRandom.hex }
pairs = uuids.zip(bytes)
hash = Hash[pairs]
Benchmark.bmbm(10) do |x|
REDIS.del(KEY)
x.report('vanilla') do
pairs.each do |key, val|
REDIS.hset(KEY, key, val)
end
end
REDIS.del(KEY)
x.report('pipelined') do
REDIS.pipelined do
pairs.each do |key, val|
REDIS.hset(KEY, key, val)
end
end
end
REDIS.del(KEY)
x.report('hmapped') do
REDIS.mapped_hmset(KEY, hash)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment