Sha256: a4a9241e479d0dc9c8f9fd0866e8cfac74b46494c6b18e022f2fb7463de25d31

Contents?: true

Size: 1.8 KB

Versions: 23

Compression:

Stored size: 1.8 KB

Contents

$:.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)

Version data entries

23 entries across 23 versions & 8 rubygems

Version Path
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/http_parser.rb-0.8.0/bench/thin.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/http_parser.rb-0.8.0/bench/thin.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/http_parser.rb-0.8.0/bench/thin.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/http_parser.rb-0.8.0/bench/thin.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/http_parser.rb-0.8.0/bench/thin.rb
http_parser.rb-0.8.0 bench/thin.rb
http_parser.rb-0.7.0 bench/thin.rb
midori_http_parser-0.6.2 bench/thin.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/http_parser.rb-0.6.0/bench/thin.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/http_parser.rb-0.6.0/bench/thin.rb
midori_http_parser-0.6.1.3 bench/thin.rb
midori_http_parser-0.6.1.3-java bench/thin.rb
midori_http_parser-0.6.1.2-java bench/thin.rb
midori_http_parser-0.6.1.2 bench/thin.rb
midori_http_parser-0.6.1.1-java bench/thin.rb
midori_http_parser-0.6.1.1 bench/thin.rb
midori_http_parser-0.6.1 bench/thin.rb
http_parser.rb-0.6.0-java bench/thin.rb
http_parser.rb-0.6.0 bench/thin.rb
http_parser.rb-0.6.0.beta.2-java bench/thin.rb