unicorn.git  about / heads / tags
Rack HTTP server for Unix and fast clients
blob fc7822c3248fb43df33b5eb43fbee3df954f9a69 1064 bytes (raw)
$ git show v0.8.1:test/benchmark/request.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 
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

git clone https://yhbt.net/unicorn.git