Created
June 4, 2010 03:47
-
-
Save fallwith/424910 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 = 3000 | |
def prep(array=[]) | |
redis = Redis.new(:host => HOST, :port => PORT, :thread_safe => true) | |
redis.del(SETNAME) | |
0.upto(SETSIZE) do |i| | |
array << i | |
redis.sadd(SETNAME, i) | |
end | |
redis | |
end | |
def del | |
redis = prep | |
redis.del(SETNAME) | |
end | |
def srems | |
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 | |
Benchmark.bmbm do |x| | |
x.report('delete the set') { del } | |
x.report('srem the set members') { srems } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment