root/benchmarks/unicode.rb

Revision 7945e32a9b7eef5967b116803fde8625b981cdb4, 1.3 KB (checked in by Mark Guzman <segfault@…>, 6 months ago)

added file encoding lines to each .rb file for 1.9
added a check for very large indexes

  • Property mode set to 100644
Line 
1# encoding: utf-8
2[ './ext', '../ext', './lib', '../lib' ].each { |l| $: << l }
3require 'rubygems'
4require 'fastxml'
5require 'hpricot'
6require 'open-uri'
7require 'benchmark'
8require 'rexml/document'
9require 'xml/libxml'
10
11test_path = './test_data/unicode.xml'
12fraw = open( test_path ) { |f| f.readlines }
13ds = fraw.join('')
14xpath_xpr = "//p"
15
16doc = hpd = rxd = lxd = nil
17fxn = hpn = rxn = lxn = nil
18
19Benchmark.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 ) }
35end
36
37puts "\nxpath expression: #{xpath_xpr}\n"
38puts "fastxml nodes: %d" % fxn.length
39puts " libxml nodes: %d" % lxn.length
40puts "hpricot nodes: %d" % hpn.length
41puts "  REXML nodes: %d" % rxn.length
Note: See TracBrowser for help on using the browser.