Browse files

Add README and minor tweak to jaxp stream

  • Loading branch information...
1 parent 5a95867 commit 5afb74bfefed1808956202321fd84d6c50393696 @nicksieger committed Nov 20, 2009
Showing with 59 additions and 1 deletion.
  1. +57 −0
  2. +2 −1 lib/xmlbench/jaxp/stream.rb
@@ -0,0 +1,57 @@
+These benchmarks were written for the article "XML Parsing in Ruby" on
+the Engine Yard blog.
+## Usage
+To use them, first ensure you have the Hpricot and Nokogiri gems
+ gem install nokogiri hpricot
+Benchmarks are run with Rake. To run a benchmark, run one of the
+- rake bench:all Run all available benchmarks
+- rake bench:<pkg> Run one package's benchmarks (where <pkg> is the
+ name of one of the subdirectories in lib/xmlbench)
+- rake bench BENCH=<file> Run one or more individual benchmarks.
+Pass N=<iterations> on the command-line to change the number of iterations.
+To add more data files, edit the Rakefile and change the `URLs` hash
+at the top. Be aware that some of the benchmarks make assumptions
+about the documents taking the form of an Atom document, so those
+benchmarks may break or be invalid.
+## Creating a new benchmark
+A benchmark is an object responds to a method named
+`#perform(xml_input)`. The input is an IO-like stream containing the
+document to be parsed. A benchmark can also respond to a method named
+`#prepare(xml_stream)`. The prepare method is called once before the
+benchmark measurement and can be used to setup any state whose
+creation shouldn't be included in the measurements.
+Each benchmark should be in its own file and have an overload for the
+Harness.parser factory method as follows:
+ class Harness
+ def self.parser
+ end
+ end
+## Notes
+If you're running benchmarks with JRuby, be aware of the following
+- To run the Nokogiri benchmarks on JRuby, you need to enable
+ objectspace (jruby -X+O; as of Nokogiri release 1.4)
+- However, turning on objectspace slows down overall JRuby
+ performance, so it's recommended to only enable it for Nokogiri.
+- To run the jaxp/stream benchmark, you need Java 6 or higher or you
+ need to manually download and install the StAX parser and APIs on
+ your classpath.
@@ -34,6 +34,7 @@ def perform(xml_input)
def self.parser
- if defined?(JRUBY_VERSION)
+ factory_available = rescue nil
+ if factory_available

0 comments on commit 5afb74b

Please sign in to comment.