tee_input: make interface more usable outside of Unicorn
[unicorn.git] / test / benchmark / request.rb
blobfc7822c3248fb43df33b5eb43fbee3df954f9a69
1 require 'benchmark'
2 require 'unicorn'
3 nr = ENV['nr'] ? ENV['nr'].to_i : 100000
5 class TestClient
6   def initialize(response)
7     @response = (response.join("\r\n") << "\r\n\r\n").freeze
8   end
9   def sysread(len, buf)
10     buf.replace(@response)
11   end
13   alias readpartial sysread
15   # old versions of Unicorn used this
16   def unicorn_peeraddr
17     '127.0.0.1'
18   end
19 end
21 small = TestClient.new([
22   'GET / HTTP/1.0',
23   'Host: localhost',
24   'Accept: */*',
25   'User-Agent: test-user-agent 0.1.0'
28 medium = TestClient.new([
29   'GET /hello/world/geturl?abcd=efg&hi#anchor HTTP/1.0',
30   'Host: localhost',
31   'Accept: */*',
32   'User-Agent: test-user-agent 0.1.0 (Mozilla compatible) 5.0 asdfadfasda'
35 include Unicorn
36 request = HttpRequest.new(Logger.new($stderr))
37 unless request.respond_to?(:reset)
38   def request.reset
39     # no-op
40   end
41 end
43 Benchmark.bmbm do |x|
44   x.report("small") do
45     for i in 1..nr
46       request.read(small)
47       request.reset
48     end
49   end
50   x.report("medium") do
51     for i in 1..nr
52       request.read(medium)
53       request.reset
54     end
55   end
56 end