| Line | |
|---|
| 1 | # encoding: utf-8 |
|---|
| 2 | [ './ext', '../ext', './lib', '../lib' ].each { |l| $: << l } |
|---|
| 3 | require 'rubygems' |
|---|
| 4 | require 'fastxml' |
|---|
| 5 | require 'hpricot' |
|---|
| 6 | require 'open-uri' |
|---|
| 7 | require 'benchmark' |
|---|
| 8 | require 'rexml/document' |
|---|
| 9 | require 'xml/libxml' |
|---|
| 10 | |
|---|
| 11 | test_path = './test_data/xslspec.xml' |
|---|
| 12 | fraw = open( test_path ) { |f| f.readlines } |
|---|
| 13 | ds = fraw.join('') |
|---|
| 14 | xpath_xpr = "//p" |
|---|
| 15 | |
|---|
| 16 | doc = hpd = rxd = lxd = nil |
|---|
| 17 | fxn = hpn = rxn = lxn = nil |
|---|
| 18 | |
|---|
| 19 | Benchmark.bm(15) do |x| |
|---|
| 20 | x.report("fastxml.new") { doc = FastXml::Doc.new( ds ) } |
|---|
| 21 | x.report("fastxml.to_s") { s = doc.to_s } |
|---|
| 22 | x.report("fastxml.search") { fxn = doc.search( xpath_xpr ) } |
|---|
| 23 | puts "" |
|---|
| 24 | x.report("hpricot.new") { hpd = Hpricot( ds ) } |
|---|
| 25 | x.report("hpricot.to_s") { s = hpd.to_s } |
|---|
| 26 | x.report("hpricot.search") { hpn = hpd.search( xpath_xpr ) } |
|---|
| 27 | puts "" |
|---|
| 28 | x.report("libxml.new") { lxd = XML::Document.file( test_path ) } |
|---|
| 29 | x.report("libxml.to_s") { s = lxd.to_s } |
|---|
| 30 | x.report("libxml.search") { lxn = lxd.find( xpath_xpr )} |
|---|
| 31 | puts "" |
|---|
| 32 | x.report("REXML.new") { rxd = REXML::Document.new( ds ) } |
|---|
| 33 | x.report("REXML.to_s") { s = rxd.to_s } |
|---|
| 34 | x.report("REXML.xpath") { rxn = REXML::XPath.match( rxd, xpath_xpr ) } |
|---|
| 35 | end |
|---|
| 36 | |
|---|
| 37 | puts "\nxpath expression: #{xpath_xpr}\n" |
|---|
| 38 | puts "fastxml nodes: %d" % fxn.length |
|---|
| 39 | puts " libxml nodes: %d" % lxn.length |
|---|
| 40 | puts "hpricot nodes: %d" % hpn.length |
|---|
| 41 | puts " REXML nodes: %d" % rxn.length |
|---|