Skip to content

Commit

Permalink
Add trivial benchmark for Rack framework to get stats for the simples…
Browse files Browse the repository at this point in the history
…t possible routing
  • Loading branch information
noahgibbs committed Jul 10, 2023
1 parent fe1cfa0 commit 3713037
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions benchmarks/rack_framework/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gem "rack"
13 changes: 13 additions & 0 deletions benchmarks/rack_framework/Gemfile.lock
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
31 changes: 31 additions & 0 deletions benchmarks/rack_framework/benchmark.rb
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

0 comments on commit 3713037

Please sign in to comment.