Skip to content

A new trie based router #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions actionpack/bench.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
require 'bundler/setup'

Bundler.setup

require 'benchmark'
require './lib/action_dispatch'

arr = ["foo", "bar", "baz", "qux", "quux", "corge", "grault", "garply"]
paths = arr.permutation(3).map { |a| "/#{a.join '/'}" }
set = ActionDispatch::Routing::RouteSet.new(ActionDispatch::TestRequest)

class HelloWorld
def initialize(response)
@response = response
end

def call(env)
[ 200, { 'Content-Type' => 'text/plain' }, [@response] ]
end
end

times = 5.times.map do |i|
set.clear!
Benchmark.measure do
set.draw do
paths.each do |path|
get path, to: HelloWorld.new(path)
end
end
end
end


# times = 5.times.map do |i|
# Benchmark.measure {
# 1000.times do |i|
# paths.each do |path|
# request = ActionDispatch::TestRequest.new
# request.path = path
#
# set.call request.env
# end
# end
# }
# end
#
sum = times.reduce(0) { |memo, obj| memo + obj.real }
mean = sum / times.length.to_f
variance = times.inject(0) { |memo, obj| memo + (obj.real - mean ) ** 2 }
variance = variance / (times.length - 1).to_f

puts times.map(&:real)

puts "Mean elapsed real time: #{mean} seconds"
puts "Standard Deviation: #{ Math.sqrt variance }"

# request = ActionDispatch::TestRequest.new
# request.path = paths.first
#
# RubyProf.start
# response = set.call request.env
# raise 'broken' unless response.first == 200
#
# (paths * 100).each do |path|
# request = ActionDispatch::TestRequest.new
# request.path = path
#
# set.call request.env
# end
#
# data = RubyProf.stop
# printer = RubyProf::GraphPrinter.new(data)
#
# printer.print STDOUT
1 change: 0 additions & 1 deletion actionpack/lib/action_dispatch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class IllegalStateError < StandardError
autoload :Static
end

autoload :Journey
autoload :MiddlewareStack, 'action_dispatch/middleware/stack'
autoload :Routing

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/http/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def url_for(options = {})
result << path
end
result << "?#{params.to_query}" unless params.empty?
result << "##{Journey::Router::Utils.escape_fragment(options[:anchor].to_param.to_s)}" if options[:anchor]
result << "##{Routing::Router::Utils.escape_fragment(options[:anchor].to_param.to_s)}" if options[:anchor]
result
end

Expand Down
5 changes: 0 additions & 5 deletions actionpack/lib/action_dispatch/journey.rb

This file was deleted.

5 changes: 0 additions & 5 deletions actionpack/lib/action_dispatch/journey/backwards.rb

This file was deleted.

162 changes: 0 additions & 162 deletions actionpack/lib/action_dispatch/journey/gtg/builder.rb

This file was deleted.

47 changes: 0 additions & 47 deletions actionpack/lib/action_dispatch/journey/gtg/simulator.rb

This file was deleted.

Loading