Created
November 15, 2009 06:55
-
-
Save actsasflinn/235063 to your computer and use it in GitHub Desktop.
FastHashRing (Ruby C Extension) vs HashRing (pure Ruby)
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
# Spoiler... | |
# user system total real | |
# Hash Ring 4.580000 0.040000 4.620000 ( 4.785069) | |
# Fash Hash Ring 0.080000 0.000000 0.080000 ( 0.087039) | |
# | |
require 'benchmark' | |
require 'rubygems' | |
require 'faker' | |
require 'hash_ring' | |
require 'fast_hash_ring' | |
servers = [] | |
16.times do |i| | |
servers << "127.0.0.#{i+1}:12345" | |
end | |
weights = {} | |
4.times do |i| | |
weights["127.0.0.#{i+1}:12345"] = 8 | |
end | |
keys = [] | |
10_000.times do |i| | |
keys << Faker::Name.name | |
end | |
Benchmark.benchmark(' ' * 20 + Benchmark::Tms::CAPTION, 20) do |b| | |
h = HashRing.new(servers, weights) | |
b.report('Hash Ring') do | |
keys.each{ |key| server = h.get_node(key) } | |
end | |
fh = FastHashRing.new(servers, weights) | |
b.report('Fash Hash Ring') do | |
keys.each{ |key| server = fh.get_node(key) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment