a bunch of useless benchmarks

This commit is contained in:
Joshua Hull 2010-05-31 21:03:29 -04:00
parent ac0d702063
commit 71d3acab3e
6 changed files with 359 additions and 0 deletions

57
benchmarks/gen2.rb Normal file
View File

@ -0,0 +1,57 @@
require 'rubygems'
require 'rbench'
#require 'lib/usher'
require 'lib/http_router'
u = HttpRouter.new
u.add('/simple') .name(:simple).compile
u.add('/simple/:variable') .name(:one_variable).compile
u.add('/simple/:var1/:var2/:var3') .name(:three_variables).compile
u.add('/simple/:v1/:v2/:v3/:v4/:v5/:v6/:v7/:v8') .name(:eight_variables).compile
u.add('/with_condition/:cond1/:cond2').matching(:cond1 => /^\d+$/, :cond2 => /^[a-z]+$/) .name(:two_conditions).compile
TIMES = 50_000
RBench.run(TIMES) do
group "named" do
report "simple" do
u.url(:simple)
end
report "one variable (through array)" do
u.url(:one_variable, 'variable')
end
report "one variable (through hash)" do
u.url(:one_variable, :variable => 'variable')
end
report "three variable (through array)" do
u.url(:three_variables, 'var1', 'var2', 'var3')
end
report "three variable (through hash)" do
u.url(:three_variables, :var1 => 'var1', :var2 => 'var2', :var3 => 'var3')
end
report "eight variable (through array)" do
u.url(:eight_variables, 'var1', 'var2', 'var3', 'var4', 'var5', 'var6', 'var7', 'var8')
end
report "eight variable (through hash)" do
u.url(:eight_variables, :v1 => 'var1', :v2 => 'var2', :v3 => 'var3', :v4 => 'var4', :v5 => 'var5', :v6 => 'var6', :v7 => 'var7', :v8 => 'var8')
end
report "three variable + three extras" do
u.url(:three_variables, :var1 => 'var1', :var2 => 'var2', :var3 => 'var3', :var4 => 'var4', :var5 => 'var5', :var6 => 'var6')
end
report "three variable + five extras" do
u.url(:three_variables, :var1 => 'var1', :var2 => 'var2', :var3 => 'var3', :var4 => 'var4', :var5 => 'var5', :var6 => 'var6', :var7 => 'var7', :var8 => 'var8')
end
end
end
puts `ps -o rss= -p #{Process.pid}`.to_i

View File

@ -0,0 +1,73 @@
require 'rubygems'
require 'rbench'
#require 'lib/usher'
require 'usher'
u = Usher.new(:generator => Usher::Util::Generators::URL.new)
u.add_route('/simple') .name(:simple)
u.add_route('/simple/:variable') .name(:one_variable)
u.add_route('/simple/:var1/:var2/:var3') .name(:three_variables)
u.add_route('/simple/:v1/:v2/:v3/:v4/:v5/:v6/:v7/:v8') .name(:eight_variables)
u.add_route('/with_condition/:cond1/:cond2', :requirements => {:cond1 => /^\d+$/, :cond2 => /^[a-z]+$/}) .name(:two_conditions)
u.add_route('/with_condition/{:cond1,^\d+$}/{:cond2,^[a-z]+$}') .name(:two_implicit_conditions)
#u.add_route('/blog/:page', :default_values => {:page => 1}) .name(:default_value)
#u.add_route('/blog', :default_values => {:page => 1}) .name(:default_value_not_as_variable)
#
TIMES = 50_000
RBench.run(TIMES) do
group "named" do
report "simple" do
u.generator.generate(:simple)
end
report "one variable (through array)" do
u.generator.generate(:one_variable, 'variable')
end
report "one variable (through hash)" do
u.generator.generate(:one_variable, :variable => 'variable')
end
report "three variable (through array)" do
u.generator.generate(:three_variables, ['var1', 'var2', 'var3'])
end
report "three variable (through hash)" do
u.generator.generate(:three_variables, :var1 => 'var1', :var2 => 'var2', :var3 => 'var3')
end
report "eight variable (through array)" do
u.generator.generate(:eight_variables, ['var1', 'var2', 'var3', 'var4', 'var5', 'var6', 'var7', 'var8'])
end
report "eight variable (through hash)" do
u.generator.generate(:eight_variables, :v1 => 'var1', :v2 => 'var2', :v3 => 'var3', :v4 => 'var4', :v5 => 'var5', :v6 => 'var6', :v7 => 'var7', :v8 => 'var8')
end
report "three variable + three extras" do
u.generator.generate(:three_variables, :var1 => 'var1', :var2 => 'var2', :var3 => 'var3', :var4 => 'var4', :var5 => 'var5', :var6 => 'var6')
end
report "three variable + five extras" do
u.generator.generate(:three_variables, :var1 => 'var1', :var2 => 'var2', :var3 => 'var3', :var4 => 'var4', :var5 => 'var5', :var6 => 'var6', :var7 => 'var7', :var8 => 'var8')
end
end
#group "defaults" do
# report "default variable" do
# u.generator.generate(:default_value)
# end
#
# report "default variable not represented in path" do
# u.generator.generate(:default_value_not_as_variable)
# end
#
#
#end
end
puts `ps -o rss= -p #{Process.pid}`.to_i

76
benchmarks/rack_mount.rb Normal file
View File

@ -0,0 +1,76 @@
require 'rubygems'
require 'rbench'
require 'rack'
require 'rack/mount'
require '../usher/lib/usher'
require 'lib/http_router'
set = Rack::Mount::RouteSet.new do |set|
set.add_route(proc{|env| [200, {'Content-type'=>'text/html'}, []]}, {:path => '/simple'}, {}, :simple)
set.add_route(proc{|env| [200, {'Content-type'=>'text/html'}, []]}, {:path => '/simple/again'}, {}, :again)
set.add_route(proc{|env| [200, {'Content-type'=>'text/html'}, []]}, {:path => '/dynamic/:variable'}, {}, :variable)
end
u = Usher::Interface.for(:rack)
u.add('/simple').to(proc{|env| [200, {'Content-type'=>'text/html'}, []]})
u.add('/simple/again').to(proc{|env| [200, {'Content-type'=>'text/html'}, []]})
u.add('/dynamic/anything').to(proc{|env| [200, {'Content-type'=>'text/html'}, []]})
hr = HttpRouter.new
hr.add('/simple').to(proc{|env| [200, {'Content-type'=>'text/html'}, []]})
hr.add('/simple/again').to(proc{|env| [200, {'Content-type'=>'text/html'}, []]})
hr.add('/dynamic/anything').to(proc{|env| [200, {'Content-type'=>'text/html'}, []]})
TIMES = 50_000
simple_env = Rack::MockRequest.env_for('/simple')
simple2_env = Rack::MockRequest.env_for('/simple/again')
simple_and_dynamic_env = Rack::MockRequest.env_for('/dynamic/anything')
RBench.run(TIMES) do
report "2 levels, static" do
set.url(simple_env, :simple)
end
report "4 levels, static" do
set.url(simple_env, :again)
end
report "4 levels, 1 dynamic" do
set.url(simple_env, :variable, {:variable => 'onemore'})
end
end
RBench.run(TIMES) do
report "2 levels, static" do
set.url(simple_env, :simple)
end
report "4 levels, static" do
set.url(simple_env, :again)
end
report "4 levels, 1 dynamic" do
set.url(simple_env, :variable, {:variable => 'onemore'})
end
end
RBench.run(TIMES) do
report "2 levels, static" do
set.url(simple_env, :simple)
end
report "4 levels, static" do
set.url(simple_env, :again)
end
report "4 levels, 1 dynamic" do
set.url(simple_env, :variable, {:variable => 'onemore'})
end
end

View File

@ -0,0 +1,50 @@
require 'rubygems'
require 'rbench'
require '../usher/lib/usher'
u = Usher::Interface.for(:rack)
u.add('/simple').to(proc{|env| [200, {'Content-type'=>'text/html'}, []]})
u.add('/simple/again').to(proc{|env| [200, {'Content-type'=>'text/html'}, []]})
u.add('/simple/again/and/again').to(proc{|env| [200, {'Content-type'=>'text/html'}, []]})
u.add('/dynamic/:variable').to(proc{|env| [200, {'Content-type'=>'text/html'}, []]})
u.add('/rails/:controller/:action/:id').to(proc{|env| [200, {'Content-type'=>'text/html'}, []]})
u.add('/greedy/{!greed,.*}').to(proc{|env| [200, {'Content-type'=>'text/html'}, []]})
TIMES = 50_000
simple_env = Rack::MockRequest.env_for('/simple')
simple2_env = Rack::MockRequest.env_for('/simple/again')
simple3_env = Rack::MockRequest.env_for('/simple/again/and/again')
simple_and_dynamic_env = Rack::MockRequest.env_for('/dynamic/anything')
simple_and_dynamic_env1 = Rack::MockRequest.env_for('/rails/controller/action/id')
simple_and_dynamic_env2 = Rack::MockRequest.env_for('/greedy/controller/action/id')
RBench.run(TIMES) do
report "2 levels, static" do
u.call(simple_env).first == 200 or raise
end
report "4 levels, static" do
u.call(simple2_env).first == 200 or raise
end
report "8 levels, static" do
u.call(simple3_env).first == 200 or raise
end
report "4 levels, 1 dynamic" do
u.call(simple_and_dynamic_env).first == 200 or raise
end
report "8 levels, 3 dynamic" do
u.call(simple_and_dynamic_env1).first == 200 or raise
end
report "4 levels, 1 greedy" do
u.call(simple_and_dynamic_env2).first == 200 or raise
end
end
puts `ps -o rss= -p #{Process.pid}`.to_i

62
benchmarks/rec2.rb Normal file
View File

@ -0,0 +1,62 @@
require 'rubygems'
require 'rbench'
require 'lib/http_router'
u = HttpRouter.new
u.add('/simple').to {|env| [200, {'Content-type'=>'text/html'}, []]}
u.add('/simple/again').compile.to {|env| [200, {'Content-type'=>'text/html'}, []]}
u.add('/simple/again/and/again').compile.to {|env| [200, {'Content-type'=>'text/html'}, []]}
u.add('/dynamic/:variable').compile.to {|env| [200, {'Content-type'=>'text/html'}, []]}
u.add('/rails/:controller/:action/:id').compile.to {|env| [200, {'Content-type'=>'text/html'}, []]}
u.add('/greedy/:greed').matching(:greed => /.*/).compile.to {|env| [200, {'Content-type'=>'text/html'}, []]}
#u.add('/greedy/hey.:greed.html').to {|env| [200, {'Content-type'=>'text/html'}, []]}
#puts Benchmark.measure {
# ('aa'..'nn').each do |first|
# ('a'..'n').each do |second|
# u.add("/#{first}/#{second}").compile
# end
# end
#
# puts "u.routes.size: #{u.routes.size}"
#}
#
TIMES = 50_000
simple_env = Rack::MockRequest.env_for('/simple')
simple2_env = Rack::MockRequest.env_for('/simple/again')
simple3_env = Rack::MockRequest.env_for('/simple/again/and/again')
simple_and_dynamic_env = Rack::MockRequest.env_for('/dynamic/anything')
simple_and_dynamic_env1 = Rack::MockRequest.env_for('/rails/controller/action/id')
simple_and_dynamic_env2 = Rack::MockRequest.env_for('/greedy/controller/action/id')
simple_and_dynamic_env3 = Rack::MockRequest.env_for('/greedy/hey.hello.html')
RBench.run(TIMES) do
report "2 levels, static" do
u.call(simple_env).first == 200 or raise
end
report "4 levels, static" do
u.call(simple2_env).first == 200 or raise
end
report "8 levels, static" do
u.call(simple3_env).first == 200 or raise
end
report "4 levels, 1 dynamic" do
u.call(simple_and_dynamic_env).first == 200 or raise
end
report "8 levels, 3 dynamic" do
u.call(simple_and_dynamic_env1).first == 200 or raise
end
report "4 levels, 1 greedy" do
u.call(simple_and_dynamic_env2).first == 200 or raise
end
end
puts `ps -o rss= -p #{Process.pid}`.to_i

View File

@ -0,0 +1,41 @@
require 'rubygems'
require 'rbench'
require 'usher'
u = Usher.new(:generator => Usher::Util::Generators::URL.new)
u.add_route('/simple')
u.add_route('/simple/again')
u.add_route('/simple/again/and/again')
u.add_route('/dynamic/:variable')
u.add_route('/rails/:controller/:action/:id')
u.add_route('/greedy/{!greed,.*}')
TIMES = 50_000
RBench.run(TIMES) do
report "2 levels, static" do
u.recognize_path('/simple')
end
report "4 levels, static" do
u.recognize_path('/simple/again')
end
report "8 levels, static" do
u.recognize_path('/simple/again/and/again')
end
report "4 levels, 1 dynamic" do
u.recognize_path('/dynamic/anything')
end
report "8 levels, 3 dynamic" do
u.recognize_path('/rails/controller/action/id')
end
report "4 levels, 1 greedy" do
u.recognize_path('/greedy/controller/action/id')
end
end