Created
October 17, 2012 02:57
-
-
Save kimoto/3903463 to your computer and use it in GitHub Desktop.
Memcached benchmark
This file contains hidden or 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
#!/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