Permalink
Browse files

Add timing test for large restful route recognition. References #10835

…[oleganza]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8673 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 355a8ff commit 630c643f5ba37cbaf541f72005e49080545bcada @jeremy jeremy committed Jan 19, 2008
Showing with 52 additions and 8 deletions.
  1. +17 −0 actionpack/test/controller/fake_controllers.rb
  2. +35 −8 actionpack/test/controller/routing_test.rb
@@ -10,6 +10,23 @@ class UserController < Class.new(ActionController::Base); end
class NewsFeedController < Class.new(ActionController::Base); end
end
+# For speed test
+class SpeedController < ActionController::Base; end
+class SearchController < SpeedController; end
+class VideosController < SpeedController; end
+class VideoFileController < SpeedController; end
+class VideoSharesController < SpeedController; end
+class VideoAbusesController < SpeedController; end
+class VideoUploadsController < SpeedController; end
+class VideoVisitsController < SpeedController; end
+class UsersController < SpeedController; end
+class SettingsController < SpeedController; end
+class ChannelsController < SpeedController; end
+class ChannelVideosController < SpeedController; end
+class SessionsController < SpeedController; end
+class LostPasswordsController < SpeedController; end
+class PagesController < SpeedController; end
+
ActionController::Routing::Routes.draw do |map|
map.route_one 'route_one', :controller => 'elsewhere', :action => 'flash_me'
map.connect ':controller/:action/:id'
@@ -84,20 +84,47 @@ def test_ignores_leading_slash
end
def test_time_recognition
- n = 10000
+ # We create many routes to make situation more realistic
+ @rs = ::ActionController::Routing::RouteSet.new
+ @rs.draw { |map|
+ map.frontpage '', :controller => 'search', :action => 'new'
+ map.resources :videos do |video|
+ video.resources :comments
+ video.resource :file, :controller => 'video_file'
+ video.resource :share, :controller => 'video_shares'
+ video.resource :abuse, :controller => 'video_abuses'
+ end
+ map.resources :abuses, :controller => 'video_abuses'
+ map.resources :video_uploads
+ map.resources :video_visits
+
+ map.resources :users do |user|
+ user.resource :settings
+ user.resources :videos
+ end
+ map.resources :channels do |channel|
+ channel.resources :videos, :controller => 'channel_videos'
+ end
+ map.resource :session
+ map.resource :lost_password
+ map.search 'search', :controller => 'search'
+ map.resources :pages
+ map.connect ':controller/:action/:id'
+ }
+ n = 1000
if RunTimeTests
GC.start
rectime = Benchmark.realtime do
n.times do
- rs.recognize_path("content")
- rs.recognize_path("content/list")
- rs.recognize_path("content/show/10")
- rs.recognize_path("admin/user")
- rs.recognize_path("admin/user/list")
- rs.recognize_path("admin/user/show/10")
+ rs.recognize_path("/videos/1234567", {:method => :get})
+ rs.recognize_path("/videos/1234567/abuse", {:method => :get})
+ rs.recognize_path("/users/1234567/settings", {:method => :get})
+ rs.recognize_path("/channels/1234567", {:method => :get})
+ rs.recognize_path("/session/new", {:method => :get})
+ rs.recognize_path("/admin/user/show/10", {:method => :get})
end
end
- puts "\n\nRecognition (RouteSet):"
+ puts "\n\nRecognition (#{rs.routes.size} routes):"
per_url = rectime / (n * 6)
puts "#{per_url * 1000} ms/url"
puts "#{1 / per_url} url/s\n\n"

0 comments on commit 630c643

Please sign in to comment.