Skip to content

Instantly share code, notes, and snippets.

@actsasflinn
Created May 22, 2009 12:38
Show Gist options
  • Save actsasflinn/116096 to your computer and use it in GitHub Desktop.
Save actsasflinn/116096 to your computer and use it in GitHub Desktop.
ruby-tokyotyrant takes @kamal's url shortener test
# URL shortener used to benchmark redis-rb and RubyRedis applied to ruby-tokyotyrant
# Script takes 1.2 seconds
require 'rubygems'
require 'benchmark'
require 'tokyo_tyrant'
puts Benchmark.realtime{
T=TokyoTyrant::DB.new('127.0.0.1', 45000)
def shorten(url)
id = T.add_int("global:next.url.id", 1) # this line accounts for 1 second of the 1.2 seconds
T.putnr("url:#{id}", url)
"http://example.com/#{id.to_i.to_s(32)}"
end
10000.times {
shorten("http://github.com/actsasflinn/ruby-tokyotyrant/tree/master")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment