minor cleanups and save a few variables
[unicorn.git] / test / benchmark / big_request.rb
blob5f2111b350569f654ed0c70e54b654d89009a6d8
1 require 'benchmark'
2 require 'tempfile'
3 require 'unicorn'
4 nr = ENV['nr'] ? ENV['nr'].to_i : 100
5 bs = ENV['bs'] ? ENV['bs'].to_i : (1024 * 1024)
6 count = ENV['count'] ? ENV['count'].to_i : 4
7 length = bs * count
8 slice = (' ' * bs).freeze
10 big = Tempfile.new('')
11 def big.unicorn_peeraddr; '127.0.0.1'; end
12 big.syswrite(
13 "PUT /hello/world/puturl?abcd=efg&hi#anchor HTTP/1.0\r\n" \
14 "Host: localhost\r\n" \
15 "Accept: */*\r\n" \
16 "Content-Length: #{length}\r\n" \
17 "User-Agent: test-user-agent 0.1.0 (Mozilla compatible) 5.0 asdfadfasda\r\n" \
18 "\r\n")
19 count.times { big.syswrite(slice) }
20 big.sysseek(0)
21 big.fsync
23 include Unicorn
24 request = HttpRequest.new(Logger.new($stderr))
26 Benchmark.bmbm do |x|
27   x.report("big") do
28     for i in 1..nr
29       request.read(big)
30       request.reset
31       big.sysseek(0)
32     end
33   end
34 end