Created
April 23, 2015 14:39
-
-
Save soveran/a331acc8726dcba4ad43 to your computer and use it in GitHub Desktop.
Initial benchmarks of Rack, Syro and Cuba.
This file contains hidden or 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
require "benchmark" | |
require "cuba" | |
require "syro" | |
class HelloWorld | |
def call(env) | |
if env['REQUEST_METHOD'] == 'GET' && env['PATH_INFO'] == '/foo/bar' | |
[200, {"Content-Type" => "text/html"}, ["hello world"]] | |
elsif env['REQUEST_METHOD'] == 'GET' && env['PATH_INFO'] == '/admin' | |
[200, {"Content-Type" => "text/html"}, ["for admins"]] | |
else | |
[404, {"Content-Type" => "text/html"}, [""]] | |
end | |
end | |
end | |
RackApp = HelloWorld.new | |
class Admin < Cuba | |
define do | |
on root, get do | |
res.write "for admins" | |
end | |
end | |
end | |
Cuba.define do | |
on "foo/bar" do | |
on root, get do | |
res.write "hello world" | |
end | |
end | |
on "admin" do | |
run Admin | |
end | |
end | |
admin = Syro.new { | |
get { | |
res.write("for admins") | |
} | |
} | |
app = Syro.new { | |
on("foo/bar") { | |
get { | |
res.write("hello world") | |
} | |
} | |
on("admin") { | |
run(admin) | |
} | |
} | |
env1 = { "REQUEST_METHOD" => "GET", "PATH_INFO" => "/foo/bar", | |
"SCRIPT_NAME" => "/" } | |
env2 = { "REQUEST_METHOD" => "GET", "PATH_INFO" => "/admin", | |
"SCRIPT_NAME" => "/" } | |
N = 10000 | |
Benchmark.bmbm { |x| | |
x.report("Rack") { | |
N.times { | |
RackApp.call(env1) | |
} | |
} | |
x.report("Cuba") { | |
N.times { | |
Cuba.call(env1) | |
} | |
} | |
x.report("Syro") { | |
N.times { | |
app.call(env1) | |
} | |
} | |
x.report("Rack/Admin") { | |
N.times { | |
RackApp.call(env2) | |
} | |
} | |
x.report("Cuba/Admin") { | |
N.times { | |
Cuba.call(env2) | |
} | |
} | |
x.report("Syro/Admin") { | |
N.times { | |
app.call(env2) | |
} | |
} | |
} |
This file contains hidden or 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
:!ruby benchmarks.rb | |
Rehearsal ---------------------------------------------- | |
Rack 0.020000 0.000000 0.020000 ( 0.020291) | |
Cuba 0.380000 0.010000 0.390000 ( 0.376348) | |
Syro 0.070000 0.000000 0.070000 ( 0.068477) | |
Rack/Admin 0.020000 0.000000 0.020000 ( 0.024030) | |
Cuba/Admin 0.620000 0.000000 0.620000 ( 0.622762) | |
Syro/Admin 0.050000 0.000000 0.050000 ( 0.050333) | |
------------------------------------- total: 1.170000sec | |
user system total real | |
Rack 0.010000 0.000000 0.010000 ( 0.017027) | |
Cuba 0.390000 0.000000 0.390000 ( 0.391857) | |
Syro 0.060000 0.000000 0.060000 ( 0.065231) | |
Rack/Admin 0.020000 0.000000 0.020000 ( 0.022116) | |
Cuba/Admin 0.380000 0.000000 0.380000 ( 0.383459) | |
Syro/Admin 0.040000 0.000000 0.040000 ( 0.036940) |
luislavena
commented
Apr 24, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment