Skip to content

Instantly share code, notes, and snippets.

@evanphx
Created April 14, 2009 06:28
Show Gist options
  • Save evanphx/95012 to your computer and use it in GitHub Desktop.
Save evanphx/95012 to your computer and use it in GitHub Desktop.
require "rubygems"
$:.push File.join("scratch", "rack-router", "lib")
require "rack/router"
class HelloApp
def call(env)
[200, {}, "Hello #{env["PATH_INFO"]}"]
end
end
app = Rack::Router.new do |r|
r.map "/", :to => HelloApp.new
r.map "/fail(/:fail)", :to => HelloApp.new
r.map "/fail2(/:fail)", :to => HelloApp.new
r.map "/fail3(/:fail)", :to => HelloApp.new
r.map "/hello(/:fail)", :to => HelloApp.new
end
require "benchmark"
env = Rack::MockRequest.env_for("/hello/foo")
p app.call(env)
profiler = Rubinius::Profiler::Instrumenter.new
(ARGV[0] || 1).to_i.times do
Benchmark.bmbm do |x|
profiler.profile do
x.report("last") do
10_000.times do
app.call(env)
end
end
end
end
end
profiler.show
sark :: git/rbx » bin/rbx scratch/rake-router.rb
[200, {}, "Hello /hello/foo"]
% cumulative self self total
time seconds seconds calls ms/call ms/call name
----------------------------------------------------------
31.81 0.00 0.00 1 0.00 0.05 #toplevel
28.47 0.00 0.00 1 0.01 0.04 Benchmark::Job#report
13.75 0.00 0.00 1 0.01 0.02 String#concat
8.23 0.00 0.00 1 0.00 0.01 Array#push
6.93 0.00 0.00 1 0.01 0.01 Array#each
6.93 0.00 0.00 1 0.01 0.01 Kernel#tainted?
1.84 0.00 0.00 1 0.00 0.00 Array#push {}
0.95 0.00 0.00 1 0.00 0.00 Array#<<
0.47 0.00 0.00 1 0.00 0.00 String#append
0.18 0.00 0.00 1 0.00 0.00 Array#set_index
0.14 0.00 0.00 1 0.00 0.00 Proc.__from_block__
0.12 0.00 0.00 1 0.00 0.00 String#length
0.11 0.00 0.00 1 0.00 0.00 Kernel#kind_of?
0.07 0.00 0.00 1 0.00 0.00 Array#at
0.00 0.00 0.00 1 0.00 0.00 Rubinius::Profiler::Instrumenter#stop
0.00 0.00 0.00 1 0.00 0.00 Rubinius::Profiler::Instrumenter#__stop__
Rehearsal ----------------------------------------
last 3.969027 0.000000 3.969027 ( 3.968996)
------------------------------- total: 3.969027sec
user system total real
last 3.976255 0.000000 3.976255 ( 3.976236)
% cumulative self self total
time seconds seconds calls ms/call ms/call name
----------------------------------------------------------
31.81 0.00 0.00 1 0.00 0.05 #toplevel
28.47 0.00 0.00 1 0.01 0.04 Benchmark::Job#report
13.75 0.00 0.00 1 0.01 0.02 String#concat
8.23 0.00 0.00 1 0.00 0.01 Array#push
6.93 0.00 0.00 1 0.01 0.01 Array#each
6.93 0.00 0.00 1 0.01 0.01 Kernel#tainted?
1.84 0.00 0.00 1 0.00 0.00 Array#push {}
0.95 0.00 0.00 1 0.00 0.00 Array#<<
0.47 0.00 0.00 1 0.00 0.00 String#append
0.18 0.00 0.00 1 0.00 0.00 Array#set_index
0.14 0.00 0.00 1 0.00 0.00 Proc.__from_block__
0.12 0.00 0.00 1 0.00 0.00 String#length
0.11 0.00 0.00 1 0.00 0.00 Kernel#kind_of?
0.07 0.00 0.00 1 0.00 0.00 Array#at
0.00 0.00 0.00 1 0.00 0.00 Rubinius::Profiler::Instrumenter#stop
0.00 0.00 0.00 1 0.00 0.00 Rubinius::Profiler::Instrumenter#__stop__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment