Created
April 13, 2009 14:53
-
-
Save whatcould/94481 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
require 'abstract_unit' | |
require 'benchmark' | |
class MemcacheClientTest < Test::Unit::TestCase | |
def setup | |
@cache_store = ActiveSupport::Cache.lookup_store(:mem_cache_store, "127.0.0.1:11211", "localhost:11211") | |
@cache_store_no_timeouts = ActiveSupport::Cache.lookup_store(:mem_cache_store,"127.0.0.1:11211", "localhost:11211",{ :timeout => nil }) | |
@test_string = "A short string, but not too short; an average-length string, let's say. Just a little more length. Ok, now we're about right." | |
@test_string_2 = "73f382c327d2fb5809f383fca29b1fa8a9931b3d316836ad8598cdb1f7105a4d98296238a451122b340259ffb0b9b5e517d8d315244fe917e3a114c5d5a367f3" | |
@test_key = 'test_string' | |
@test_key_2 = 'test_string_2' | |
@cache_store.write(@test_key,@test_string) | |
@cache_store.write(@test_key_2,@test_string_2) | |
@cache_store_no_timeouts.write(@test_key,@test_string) | |
@cache_store_no_timeouts.write(@test_key_2,@test_string_2) | |
end | |
def test_benchmark_cache_read | |
puts "\nWith timeouts:" | |
run_benchmark(@cache_store) | |
end | |
def test_benchmark_cache_read_no_timeoutes | |
puts "\nNo timeouts:" | |
run_benchmark(@cache_store_no_timeouts) | |
end | |
def run_benchmark(cache_store) | |
prime = cache_store.read(@test_key) | |
puts "memcache_client version: " + cache_store.instance_variable_get(:@data).class::VERSION | |
ms = Benchmark.measure do | |
10000.times do | |
cache_store.read(@test_key) | |
cache_store.read(@test_key_2) | |
end | |
end | |
puts ms | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment