Permalink
Browse files

Standalone benchmark with benchmark_suite

Thin's parser doesn't work on JRuby so the thin.rb benchmark comparison
won't even run there.

This is a standalone benchmark that uses Evan Phoenix's benchmark_suite
and benchmarks the speed of parsing a HTTP request taken from Chrome.
  • Loading branch information...
1 parent 503f659 commit 450ebe17f6eceb23673e9650ab0e254f15d9ae2c @tarcieri tarcieri committed Mar 11, 2012
Showing with 34 additions and 2 deletions.
  1. +9 −2 Gemfile.lock
  2. +23 −0 bench/standalone.rb
  3. +2 −0 http_parser.rb.gemspec
View
11 Gemfile.lock
@@ -1,13 +1,17 @@
PATH
remote: .
specs:
- http_parser.rb (0.5.2)
+ http_parser.rb (0.5.3)
GEM
remote: http://rubygems.org/
specs:
+ benchmark_suite (0.8.0)
diff-lcs (1.1.2)
+ ffi (1.0.11)
+ ffi (1.0.11-java)
json (1.5.1)
+ json (1.5.1-java)
rake (0.9.2)
rake-compiler (0.7.9)
rake
@@ -19,12 +23,15 @@ GEM
rspec-expectations (2.4.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.4.0)
- yajl-ruby (0.8.2)
+ yajl-ruby (1.1.0)
PLATFORMS
+ java
ruby
DEPENDENCIES
+ benchmark_suite
+ ffi
http_parser.rb!
json (>= 1.4.6)
rake-compiler (>= 0.7.9)
View
23 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
View
2 http_parser.rb.gemspec
@@ -16,6 +16,8 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rake-compiler', '>= 0.7.9'
s.add_development_dependency 'rspec', '>= 2.0.1'
s.add_development_dependency 'json', '>= 1.4.6'
+ s.add_development_dependency 'benchmark_suite'
+ s.add_development_dependency 'ffi'
if RUBY_PLATFORM =~ /java/
s.add_development_dependency 'jruby-openssl'

0 comments on commit 450ebe1

Please sign in to comment.