Skip to content

Instantly share code, notes, and snippets.

@ctrochalakis
Created October 17, 2010 07:06
Show Gist options
  • Save ctrochalakis/630620 to your computer and use it in GitHub Desktop.
Save ctrochalakis/630620 to your computer and use it in GitHub Desktop.
Benchmarking redis sinit command
require 'redis'
require 'benchmark'
$redis = Redis.new
#$redis.flushall
array_size = Integer(ARGV.first)
a = Array.new(array_size) { rand(1_000_000) }
a = a.uniq
puts "Array size #{a.size}"
Benchmark.bm(100) do |x|
x.report('simple sadd') {
$redis.del 'set1'
a.each { |l|
$redis.sadd 'set1', l
}
}
x.report('sadd pipelined') {
$redis.del 'set2'
$redis.pipelined do
a.each { |l| $redis.sadd 'set2', l }
end
}
x.report('sadd pipelined (force hash table)') {
$redis.del 'set4'
$redis.pipelined do
$redis.sadd 'set4', 'ht'
a.each { |l| $redis.sadd 'set4', l }
$redis.srem 'set4', 'ht'
end
}
x.report('sinit') {
$redis.sinit 'set3', *a
}
x.report("ping pipelined") {
$redis.pipelined do
a.size.times { $redis.ping }
end
}
end
# Output:
#
# Array size 9942
# user system total real
# simple sadd 0.370000 0.150000 0.520000 ( 0.704810)
# sadd pipelined 0.140000 0.000000 0.140000 ( 0.168001)
# sadd pipelined (force hash table) 0.120000 0.010000 0.130000 ( 0.154536)
# sinit 0.020000 0.000000 0.020000 ( 0.037388)
# ping pipelined 0.100000 0.000000 0.100000 ( 0.092546)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment