Skip to content

Instantly share code, notes, and snippets.

@tarcieri
Created March 11, 2012 00:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarcieri/2014252 to your computer and use it in GitHub Desktop.
Save tarcieri/2014252 to your computer and use it in GitHub Desktop.
http_parser.rb benchmark
require 'rubygems'
require 'http/parser' # needs http_parser.rb gem
require 'benchmark/ips' # needs benchmark_suite gem
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
╭─tony@wintermute ~ ‹ruby-1.9.3›
╰─$ ruby http_parser_benchmark.rb
instance 1296541.0 (±7.0%) i/s - 6483620 in 5.019923s (cycle=45340)
parsing 103330.0 (±3.6%) i/s - 518378 in 5.024443s (cycle=8498)
╭─tony@wintermute ~ ‹jruby-1.6.7›
╰─$ ruby http_parser_benchmark.rb
instance 1379087.6 (±4.3%) i/s - 6878868 in 4.998682s (cycle=25572)
parsing 54545.4 (±2.1%) i/s - 273680 in 5.019850s (cycle=3421)
# Running the unreleased code from HEAD with Charlie's tune-ups looks better
instance 1265907.7 (±6.6%) i/s - 6294810 in 4.996826s (cycle=28355)
parsing 69250.0 (±3.7%) i/s - 346098 in 5.005262s (cycle=4677)
╭─tony@wintermute ~ ‹rbx-head›
╰─$ ruby http_parser_benchmark.rb
instance 515147.6 (±40.1%) i/s - 1671122 in 5.172464s (cycle=20134)
parsing 21778.8 (±7.2%) i/s - 110160 in 5.082587s (cycle=1836)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment