Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Router Benchmark
require "benchmark"
tree_router = nil
regexp_router = nil
Benchmark::bmbm do |x|
tree_router = Router.new
regexp_router = Set.new
x.report("INSERTION: Tree") do
1000.times do |i|
tree_router.register("/users/#{i}/edit", i)
end
end
x.report("INSERTION: Regexp") do
1000.times do |i|
regexp_router << [ /\/users\/(#{i})\/edit/, i ]
end
end
end
Benchmark::bmbm do |x|
x.report("MATCHING: Tree") do
10_000.times do
tree_router.search "/users/#{rand(1000)}/edit"
end
end
x.report("MATCHING: Regexp") do
10_000.times do
regexp_router.detect { |pair| "/users/#{rand(1000)}/edit" =~ pair[0] }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.