Skip to content

Instantly share code, notes, and snippets.

@ktheory
Created December 21, 2015 19:06
Show Gist options
  • Save ktheory/e62bc43900745d54eb4f to your computer and use it in GitHub Desktop.
Save ktheory/e62bc43900745d54eb4f to your computer and use it in GitHub Desktop.
Rack::Response#redirect? benchmark
#!/usr/bin/env ruby
require 'benchmark'
$: << './lib'
require 'rack'
n = 1_000_000
response = Rack::Response.new
response.status = 301
class Rack::Response
def redirect_orig?
[301, 302, 303, 307, 308].include? status
end
end
Benchmark.bm do |x|
x.report { n.times { response.redirect? } }
x.report { n.times { response.redirect_orig? } }
end
$ ruby bench.rb
user system total real
0.150000 0.000000 0.150000 ( 0.151224)
0.330000 0.010000 0.340000 ( 0.337856)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment