Sha256: 04aae03d19841bebcb5ae40c22a5672f9a3e36ab9669b322b5f227b0f1ee3c28

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

require 'benchmark'
require 'unicorn'
nr = ENV['nr'] ? ENV['nr'].to_i : 100000

class TestClient
  def initialize(response)
    @response = (response.join("\r\n") << "\r\n\r\n").freeze
  end
  def sysread(len, buf)
    buf.replace(@response)
  end

  alias readpartial sysread

  # old versions of Unicorn used this
  def unicorn_peeraddr
    '127.0.0.1'
  end
end

small = TestClient.new([
  'GET / HTTP/1.0',
  'Host: localhost',
  'Accept: */*',
  'User-Agent: test-user-agent 0.1.0'
])

medium = TestClient.new([
  'GET /hello/world/geturl?abcd=efg&hi#anchor HTTP/1.0',
  'Host: localhost',
  'Accept: */*',
  'User-Agent: test-user-agent 0.1.0 (Mozilla compatible) 5.0 asdfadfasda'
])

include Unicorn
request = HttpRequest.new(Logger.new($stderr))
unless request.respond_to?(:reset)
  def request.reset
    # no-op
  end
end

Benchmark.bmbm do |x|
  x.report("small") do
    for i in 1..nr
      request.read(small)
      request.reset
    end
  end
  x.report("medium") do
    for i in 1..nr
      request.read(medium)
      request.reset
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
unicorn-0.8.4 test/benchmark/request.rb
unicorn-0.8.2 test/benchmark/request.rb
unicorn-0.8.3 test/benchmark/request.rb
unicorn-0.9.0 test/benchmark/request.rb
unicorn-0.9.1 test/benchmark/request.rb
unicorn-0.9.2 test/benchmark/request.rb
unicorn-0.8.0 test/benchmark/request.rb
unicorn-0.8.1 test/benchmark/request.rb