Skip to content

Instantly share code, notes, and snippets.

@ang3lkar
Created November 25, 2019 09:32
Show Gist options
  • Save ang3lkar/8b7fbbd387e57dc0943ddc4cd885dd33 to your computer and use it in GitHub Desktop.
Save ang3lkar/8b7fbbd387e57dc0943ddc4cd885dd33 to your computer and use it in GitHub Desktop.
Benchmark Rails middleware
# Open an Rails console and paste these below.
# (exit and open another in case of edit)
noop = Proc.new {[200, {}, ["hello"]]}
request = Rack::MockRequest.new(noop)
Rails.configuration.middleware = Rails.configuration.middleware.dup
Benchmark.ips do |x|
x.config(time: 250, warmup: 5)
x.report("With logging middleware") { request.get("/") }
Rails.configuration.middleware.delete RailsSemanticLogger::Rack::Logger
x.report("Without logging middleware") { request.get("/") }
x.compare!
end
@ang3lkar
Copy link
Author

Warming up --------------------------------------
With logging middleware
                         4.853k i/100ms
Without logging middleware
                         4.639k i/100ms
Calculating -------------------------------------
With logging middleware
                         50.908k (±18.2%) i/s -     12.200M in 250.073357s
Without logging middleware
                         51.718k (±19.4%) i/s -     12.275M in 250.033135s

Comparison:
Without logging middleware:    51717.7 i/s
With logging middleware:    50907.6 i/s - same-ish: difference falls within error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment