-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add trivial benchmark for Rack framework to get stats for the simples…
…t possible routing
- Loading branch information
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "rack" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
rack (3.0.8) | ||
|
||
PLATFORMS | ||
arm64-darwin-21 | ||
|
||
DEPENDENCIES | ||
rack | ||
|
||
BUNDLED WITH | ||
2.4.13 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require "harness" | ||
|
||
Dir.chdir(__dir__) | ||
use_gemfile | ||
|
||
require "rack" | ||
#require "rack/builder" | ||
|
||
# Start a server | ||
app = Rack::Builder.new do | ||
#use Rack::CommonLogger | ||
map "/ok" do | ||
run lambda { |env| [200, {'content-type' => 'text/plain'}, ['OK']] } | ||
end | ||
end | ||
|
||
#run app | ||
|
||
run_benchmark(10) do | ||
10_000.times do | ||
# The app may mutate `env`, so we need to create one every time. | ||
env = Rack::MockRequest::env_for("http://localhost/ok") | ||
|
||
response = app.call(env) | ||
unless response[0] == 200 | ||
raise "HTTP response is #{response.first.inspect} instead of 200. Is the benchmark app properly set up? See README.md." | ||
end | ||
end | ||
end |