Skip to content

Instantly share code, notes, and snippets.

@fallwith
Created June 4, 2010 03:47
Show Gist options
  • Save fallwith/424910 to your computer and use it in GitHub Desktop.
Save fallwith/424910 to your computer and use it in GitHub Desktop.
#!/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