-
-
Save theojulienne/e91fc338d180e1710e29c81a5d701fab to your computer and use it in GitHub Desktop.
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
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
gem "rails", github: 'rails/rails' | |
gem "benchmark-ips" | |
gem "stackprof" | |
end | |
require "action_controller" | |
class FooController < ActionController::Base; end | |
result = Benchmark.ips do |x| | |
rs_simple = ActionDispatch::Routing::RouteSet.new | |
rs_simple.draw do | |
(1..1000).each do |i| | |
get "/foo/bar/thing_#{i}", to: "foo#bar#{i}" | |
end | |
get "/blah", to: 'foo#base' | |
end | |
x.report("without params") { | |
rs_simple.recognize_path("/blah") | |
rs_simple.recognize_path("/foo/bar/thing_99") | |
} | |
rs_params = ActionDispatch::Routing::RouteSet.new | |
rs_params.draw do | |
(1..1000).each do |i| | |
get "/:user/:repo/thing_#{i}", to: "foo#bar#{i}" | |
end | |
get "/:foo", to: 'foo#base' | |
end | |
x.report("params without constraints") { | |
rs_params.recognize_path("/blah") | |
rs_params.recognize_path("/foo/bar/thing_99") | |
} | |
rs_constraints = ActionDispatch::Routing::RouteSet.new | |
rs_constraints.draw do | |
(1..1000).each do |i| | |
get "/:user/:repo/thing_#{i}", to: "foo#bar#{i}", user: /[a-zA-Z0-9]+/, repo: /[a-zA-Z0-9]+/ | |
end | |
get "/:foo", to: 'foo#base' | |
end | |
x.report("params with constraints") { | |
rs_constraints.recognize_path("/blah") | |
rs_constraints.recognize_path("/foo/bar/thing_99") | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment