summaryrefslogtreecommitdiff
path: root/vendor/bundle/ruby/3.4.0/gems/http_parser.rb-0.8.0/bench
diff options
context:
space:
mode:
authorBenjamin Sanders <ben@Benjamins-MacBook-Pro.local>2025-10-11 10:34:24 -0400
committerBenjamin Sanders <ben@Benjamins-MacBook-Pro.local>2025-10-11 10:34:24 -0400
commit5571dc766e2143e39762ff0b47c41d1c2e154f4c (patch)
treef4f124d314a7e76c04484515aa0fd1f2e271a601 /vendor/bundle/ruby/3.4.0/gems/http_parser.rb-0.8.0/bench
parent359f3309c97fc894b63e0a295c76ab298504d635 (diff)
Vendor bundled gems for deployment
Diffstat (limited to 'vendor/bundle/ruby/3.4.0/gems/http_parser.rb-0.8.0/bench')
-rwxr-xr-xvendor/bundle/ruby/3.4.0/gems/http_parser.rb-0.8.0/bench/standalone.rb23
-rw-r--r--vendor/bundle/ruby/3.4.0/gems/http_parser.rb-0.8.0/bench/thin.rb58
2 files changed, 81 insertions, 0 deletions
diff --git a/vendor/bundle/ruby/3.4.0/gems/http_parser.rb-0.8.0/bench/standalone.rb b/vendor/bundle/ruby/3.4.0/gems/http_parser.rb-0.8.0/bench/standalone.rb
new file mode 100755
index 0000000..6b4dcb6
--- /dev/null
+++ b/vendor/bundle/ruby/3.4.0/gems/http_parser.rb-0.8.0/bench/standalone.rb
@@ -0,0 +1,23 @@
+#!/usr/bin/env ruby
+$:.unshift File.dirname(__FILE__) + "/../lib"
+require "rubygems"
+require "http/parser"
+require "benchmark/ips"
+
+request = <<-REQUEST
+GET / HTTP/1.1
+Host: www.example.com
+Connection: keep-alive
+User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.78 S
+Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
+Accept-Encoding: gzip,deflate,sdch
+Accept-Language: en-US,en;q=0.8
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
+
+REQUEST
+request.gsub!(/\n/m, "\r\n")
+
+Benchmark.ips do |ips|
+ ips.report("instance") { Http::Parser.new }
+ ips.report("parsing") { Http::Parser.new << request }
+end
diff --git a/vendor/bundle/ruby/3.4.0/gems/http_parser.rb-0.8.0/bench/thin.rb b/vendor/bundle/ruby/3.4.0/gems/http_parser.rb-0.8.0/bench/thin.rb
new file mode 100644
index 0000000..fe0dd6d
--- /dev/null
+++ b/vendor/bundle/ruby/3.4.0/gems/http_parser.rb-0.8.0/bench/thin.rb
@@ -0,0 +1,58 @@
+$:.unshift File.dirname(__FILE__) + "/../lib"
+require "rubygems"
+require "thin_parser"
+require "http_parser"
+require "benchmark"
+require "stringio"
+
+data = "POST /postit HTTP/1.1\r\n" +
+ "Host: localhost:3000\r\n" +
+ "User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9\r\n" +
+ "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\r\n" +
+ "Accept-Language: en-us,en;q=0.5\r\n" +
+ "Accept-Encoding: gzip,deflate\r\n" +
+ "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n" +
+ "Keep-Alive: 300\r\n" +
+ "Connection: keep-alive\r\n" +
+ "Content-Type: text/html\r\n" +
+ "Content-Length: 37\r\n" +
+ "\r\n" +
+ "name=marc&email=macournoyer@gmail.com"
+
+def thin(data)
+ env = {"rack.input" => StringIO.new}
+ Thin::HttpParser.new.execute(env, data, 0)
+ env
+end
+
+def http_parser(data)
+ body = StringIO.new
+ env = nil
+
+ parser = HTTP::RequestParser.new
+ parser.on_headers_complete = proc { |e| env = e }
+ parser.on_body = proc { |c| body << c }
+ parser << data
+
+ env["rack-input"] = body
+ env
+end
+
+# p thin(data)
+# p http_parser(data)
+
+TESTS = 30_000
+Benchmark.bmbm do |results|
+ results.report("thin:") { TESTS.times { thin data } }
+ results.report("http-parser:") { TESTS.times { http_parser data } }
+end
+
+# On my MBP core duo 2.2Ghz
+# Rehearsal ------------------------------------------------
+# thin: 1.470000 0.000000 1.470000 ( 1.474737)
+# http-parser: 1.270000 0.020000 1.290000 ( 1.292758)
+# --------------------------------------- total: 2.760000sec
+#
+# user system total real
+# thin: 1.150000 0.030000 1.180000 ( 1.173767)
+# http-parser: 1.250000 0.010000 1.260000 ( 1.263796)