Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add README and minor tweak to jaxp stream

  • Loading branch information...
commit 5afb74bfefed1808956202321fd84d6c50393696 1 parent 5a95867
Nick Sieger authored November 20, 2009
57  README.md
Source Rendered
... ...
@@ -0,0 +1,57 @@
  1
+These benchmarks were written for the article "XML Parsing in Ruby" on
  2
+the Engine Yard blog.
  3
+
  4
+http://engineyard.com/blog/...
  5
+
  6
+## Usage
  7
+
  8
+To use them, first ensure you have the Hpricot and Nokogiri gems
  9
+installed.
  10
+
  11
+    gem install nokogiri hpricot
  12
+
  13
+Benchmarks are run with Rake. To run a benchmark, run one of the
  14
+following:
  15
+
  16
+- rake bench:all     Run all available benchmarks
  17
+- rake bench:<pkg>   Run one package's benchmarks (where <pkg> is the
  18
+                     name of one of the subdirectories in lib/xmlbench)
  19
+- rake bench BENCH=<file> Run one or more individual benchmarks.
  20
+
  21
+Pass N=<iterations> on the command-line to change the number of iterations.
  22
+
  23
+To add more data files, edit the Rakefile and change the `URLs` hash
  24
+at the top. Be aware that some of the benchmarks make assumptions
  25
+about the documents taking the form of an Atom document, so those
  26
+benchmarks may break or be invalid.
  27
+
  28
+## Creating a new benchmark
  29
+
  30
+A benchmark is an object responds to a method named
  31
+`#perform(xml_input)`. The input is an IO-like stream containing the
  32
+document to be parsed. A benchmark can also respond to a method named
  33
+`#prepare(xml_stream)`. The prepare method is called once before the
  34
+benchmark measurement and can be used to setup any state whose
  35
+creation shouldn't be included in the measurements.
  36
+
  37
+Each benchmark should be in its own file and have an overload for the
  38
+Harness.parser factory method as follows:
  39
+
  40
+    class Harness
  41
+      def self.parser
  42
+        MyParser.new
  43
+      end
  44
+    end
  45
+
  46
+## Notes
  47
+
  48
+If you're running benchmarks with JRuby, be aware of the following
  49
+issues:
  50
+
  51
+- To run the Nokogiri benchmarks on JRuby, you need to enable
  52
+  objectspace (jruby -X+O; as of Nokogiri release 1.4)
  53
+- However, turning on objectspace slows down overall JRuby
  54
+  performance, so it's recommended to only enable it for Nokogiri.
  55
+- To run the jaxp/stream benchmark, you need Java 6 or higher or you
  56
+  need to manually download and install the StAX parser and APIs on
  57
+  your classpath.
3  lib/xmlbench/jaxp/stream.rb
@@ -34,6 +34,7 @@ def perform(xml_input)
34 34
   end
35 35
 
36 36
   def self.parser
37  
-    Harness::JAXP::Stream.new if defined?(JRUBY_VERSION)
  37
+    factory_available = javax.xml.stream.XMLInputFactory rescue nil
  38
+    Harness::JAXP::Stream.new if factory_available
38 39
   end
39 40
 end

0 notes on commit 5afb74b

Please sign in to comment.
Something went wrong with that request. Please try again.