Created
October 1, 2013 08:10
-
-
Save dim/6775254 to your computer and use it in GitHub Desktop.
Integration benchmark for redis BITPOS command
This file contains 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
# Integration benchmark for redis BITPOS command | |
require 'redis' | |
require 'benchmark' | |
random = Random.new(1) | |
redis = Redis.new timeout: 60 | |
bitlen = 10_000 | |
tmpkey = "__rb__bs__" | |
server = File.expand_path('../src/redis-server', __FILE__) | |
svrpid = spawn [server, File.expand_path('../redis.conf', __FILE__)].join(" ") | |
count = 0 | |
real = 0 | |
script = <<-LUA | |
local key = '#{tmpkey}' | |
local count = 0 | |
for i=1,10000 do | |
count = #redis.call('bitpos', key) | |
end | |
return count | |
LUA | |
at_exit do | |
redis.del tmpkey rescue nil | |
Process.kill(:TERM, svrpid) | |
sleep(1) | |
end | |
sparse = (1..(bitlen*0.001).to_i).map do |_| | |
random.rand(bitlen) | |
end.uniq | |
medium = (1..(bitlen*0.1).to_i).map do |_| | |
random.rand(bitlen) | |
end.uniq | |
dense = (1..bitlen).map do |_| | |
random.rand(bitlen) | |
end.uniq | |
sleep(1) | |
redis.config :set, "lua-time-limit", 60_000 | |
redis.config :get, "lua-time-limit" | |
puts "--> Benchmarking sparse: #{sparse.size} bits set out of #{bitlen}" | |
redis.pipelined do | |
redis.del tmpkey | |
sparse.each {|o| redis.setbit(tmpkey, o, 1) } | |
end | |
real = Benchmark.realtime do | |
count = redis.eval script | |
end | |
puts " Completed in #{real.round(3)}s returning #{count}" | |
puts "--> Benchmarking medium: #{medium.size} bits set out of #{bitlen}" | |
redis.pipelined do | |
redis.del tmpkey | |
medium.each {|o| redis.setbit(tmpkey, o, 1) } | |
end | |
real = Benchmark.realtime do | |
count = redis.eval script | |
end | |
puts " Completed in #{real.round(3)}s returning #{count}" | |
puts "--> Benchmarking dense: #{dense.size} bits set out of #{bitlen}" | |
redis.pipelined do | |
redis.del tmpkey | |
dense.each {|o| redis.setbit(tmpkey, o, 1) } | |
end | |
real = Benchmark.realtime do | |
count = redis.eval script | |
end | |
puts " Completed in #{real.round(3)}s returning #{count}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment