Created
February 14, 2011 17:17
-
-
Save n0ts/826192 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 'rubygems' | |
require 'benchmark' | |
gem 'dalli', '=1.0.2' | |
require 'dalli' | |
TEST_DATA_NUM = 100 | |
$memcached = Dalli::Client.new('127.0.0.1:11211') | |
# ベンチマークを計測する | |
Benchmark.bm do |x| | |
x.report('dalli - set') { | |
a = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a | |
TEST_DATA_NUM.times {|i| | |
data = '' | |
((i + 1) * 10).times { data += a[rand(a.size)] } | |
$memcached.set((i + 1).to_s, data) | |
} | |
} | |
x.report('dalli - get_multi 1 key') { | |
1.step(TEST_DATA_NUM, 1){|i| | |
if $memcached.get(i.to_s) == nil | |
raise 'Could not get data from memcached - memcached - 1' | |
end | |
} | |
} | |
x.report('dalli - get_multi 5 keys') { | |
1.step(TEST_DATA_NUM, 5){|i| | |
keys = [] | |
5.times {|ii| keys << (i + ii).to_s } | |
if $memcached.get_multi(keys) == nil | |
raise "Could not get data from memcached - memcached - 5 #{keys.join(',')}" | |
end | |
} | |
} | |
x.report('dalli - get_multi 10 keys') { | |
1.step(TEST_DATA_NUM, 10){|i| | |
keys = [] | |
10.times {|ii| keys << (i + ii).to_s } | |
if $memcached.get_multi(keys) == nil | |
raise 'Could not get data from memcached - memcached - 10' | |
end | |
} | |
} | |
x.report('dalli - get_multi 100 keys') { | |
1.step(TEST_DATA_NUM, 100){|i| | |
keys = [] | |
100.times {|ii| keys << (i + ii).to_s } | |
if $memcached.get_multi(keys) == nil | |
raise 'Could not get data from memcached - memcached - 100' | |
end | |
} | |
} | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment