-
-
Save nateware/366265 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'redis/objects' | |
require 'benchmark' | |
$redis = Redis.new(:host => '127.0.0.1', :port => 6379, :thread_safe => true) | |
require 'redis/sorted_set' | |
lb = Redis::SortedSet.new('rank:overall:by_points') | |
# lb.clear | |
players = %W{Matt James Pete Nate Luisa Manu Josh} | |
start = Time.now | |
players.each do |player| | |
lb[player] = rand(20_000) | |
end | |
total_players = 100_000 | |
rank_requests = 1_000 | |
Benchmark.bm(40) do |bm| | |
bm.report "insert #{total_players} items" do | |
(100_000 - players.size).times do |n| | |
lb["player_#{n}"] = rand(20_000) | |
end | |
end | |
bm.report "#{rank_requests} rank requests" do | |
rank_requests.times{lb.rank('Matt'); lb.rank('Pete')} | |
end | |
bm.report "#{rank_requests} range calls" do | |
rank_requests.times do | |
lb['Matt'] = rand(20_000) | |
lb['Pete'] = rand(20_000) | |
lb.range(0,1023, :withscores => true) | |
end | |
end | |
bm.report "native client: rank overall points" do | |
rank_requests.times{ $redis.zrange 'rank:overall:by_points', 0, 1023, 'withscores' } | |
end | |
bm.report "redis-objects: rank overall points" do | |
rank_requests.times{ lb.range(0, 1023, :withscores => true) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment