Last active
December 28, 2015 17:39
-
-
Save yonkeltron/7537277 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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) |
This file contains hidden or 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
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