Skip to content

Instantly share code, notes, and snippets.

@mattetti
Created April 14, 2010 19:27
Show Gist options
  • Save mattetti/366212 to your computer and use it in GitHub Desktop.
Save mattetti/366212 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'redis/objects'
$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
(100_000 - players.size).times do |n|
lb["player_#{n}"] = rand(20_000)
end
puts "inserting #{total_players} rank items took: #{Time.now - start} seconds"
start = Time.now
1_000.times{lb.rank('Matt'); lb.rank('Pete')}
puts "2,000 individual rank requests took #{Time.now - start}"
start = Time.now
lb['Matt'] = rand(20_000); lb['Pete'] = rand(20_000); lb.range(0,1023, :withscores => true)
10.times{ lb.range(0, 1023, :withscores => true) }
# 10_000.times{lb['Matt'] = rand(20_000); lb['Pete'] = rand(20_000); lb.range(0,1023, :withscores => true)}
puts "Updating 2 entries and getting the updating 1024 first ranks took #{Time.now - start}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment