Created
June 4, 2010 02:28
-
-
Save fallwith/424838 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby -w | |
require 'redis' | |
require 'benchmark' | |
HOST = 'localhost' | |
PORT = 6379 | |
SETNAME = 'benchmark_testing_set' | |
SETSIZE = 7500 | |
def prep(array) | |
redis = Redis.new(:host => HOST, :port => PORT, :thread_safe => true) | |
redis.del(SETNAME) | |
0.upto(SETSIZE-1) do |i| | |
array << i | |
redis.sadd(SETNAME, i) | |
end | |
redis | |
end | |
def vanilla_redis | |
ids = [] | |
redis = prep(ids) | |
ids.each do |id| | |
redis.srem(SETNAME, id) | |
end | |
end | |
def pipelined_redis | |
ids = [] | |
redis = prep(ids) | |
pipeline = Redis::Pipeline.new(Redis.new(:host => HOST, :port => PORT, :thread_safe => true)) | |
ids.each do |id| | |
pipeline.srem(SETNAME, id) | |
end | |
pipeline.execute | |
end | |
def multi_redis | |
ids = [] | |
redis = prep(ids) | |
redis.multi | |
ids.each do |id| | |
redis.srem(SETNAME, id) | |
end | |
redis.exec | |
end | |
Benchmark.bmbm do |x| | |
x.report('vanilla redis') { vanilla_redis } | |
x.report('pipelined redis') { pipelined_redis } | |
x.report('multi redis') { multi_redis } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment