Skip to content

Instantly share code, notes, and snippets.

@kimoto
Created October 17, 2012 02:57
Show Gist options
  • Save kimoto/3903463 to your computer and use it in GitHub Desktop.
Save kimoto/3903463 to your computer and use it in GitHub Desktop.
Memcached benchmark
#!/bin/env ruby
# encoding: utf-8
# Author: kimoto
require 'memcache'
def benchmark(desc, &proc)
puts ">>> #{desc}"
start = Time.now
begin
proc.call
rescue => ex
STDERR.puts ex
end
stop = Time.now
stop - start
end
cache = Memcache.new(:server => 'localhost:11211')
requests = 1000
seconds = benchmark "memcached Set Speed" do
requests.times{ |n|
key = "key_#{n}"
cache.set(key, "http://http://kimoto.hatenablog.com/?n=#{n}")
}
end
puts "#{seconds} seconds"
puts "#{(requests / seconds)} req/sec"
puts
seconds = benchmark "memcached Get Speed" do
requests.times{ |n|
key = "key_#{n}"
cache.get(key)
}
end
puts "#{seconds} seconds"
puts "#{(requests / seconds)} req/sec"
puts
seconds = benchmark "memcached Not found Get Speed" do
requests.times{ |n|
key = "nfk_#{n}"
cache.get(key)
}
end
puts "#{seconds} seconds"
puts "#{(requests / seconds)} req/sec"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment