about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-07-04 19:56:38 +0000
committerEric Wong <e@80x24.org>2019-07-04 20:13:45 +0000
commit10142db47f4b03eb00749feda660df567fde7276 (patch)
treef92a2f4a2463ce500911cbb04750fffb29df9526
parent5e3d05997769dd270123b9c2479938704de078de (diff)
downloadunicorn-10142db47f4b03eb00749feda660df567fde7276.tar.gz
Some changes coming to the HTTP parser, so might as well throw
some sort of benchmark we can work with to validate
improvements.
-rw-r--r--test/benchmark/http_parser.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/test/benchmark/http_parser.rb b/test/benchmark/http_parser.rb
new file mode 100644
index 0000000..9509637
--- /dev/null
+++ b/test/benchmark/http_parser.rb
@@ -0,0 +1,43 @@
+# encoding: binary
+# benchmark for HTTP parser hackers:
+#   make http && ruby -I lib:ext/unicorn_http test/benchmark/http_parser.rb
+require 'unicorn'
+require 'optparse'
+require 'benchmark'
+$stdout.sync = true
+extra = []
+nr = 100000
+op = OptionParser.new("", 24, '  ') do |opts|
+  opts.banner = "Usage: #$0"
+  opts.separator "#$0 options:"
+  # some of these switches exist for rackup command-line compatibility,
+
+  opts.on('-n NUM', Integer, 'number of iterations') { |i| nr = i }
+  opts.on('-H HEADER:VALUE', String) { |h| extra << h }
+  opts.parse! ARGV
+end
+extra << '' if extra[0]
+
+payload = <<"".freeze
+GET /nowhere HTTP/1.0\r
+Host: example.com\r
+Accept-Encoding: gzip\r
+Accept-Language: en-US\r
+User-Agent: curl/7.52.1\r
+Accept: */*\r
+Referer: https://example.com/eye-kant-spel\r
+Cache-Control: max-age=0\r
+X-Forwarded-For: 0.6.6.6\r
+#{extra.join("\r\n")}\r
+
+hp = Unicorn::HttpParser.new
+puts payload.gsub(/^/, '> ')
+puts "#{nr} iterations"
+res = Benchmark.measure do
+  nr.times do
+    hp.buf << payload
+    hp.parse or abort
+    hp.clear
+  end
+end
+puts Benchmark::CAPTION, res