root/benchmarks/speedtest.rb

Revision 7945e32a9b7eef5967b116803fde8625b981cdb4, 1.8 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/hasno_feed.xml'
12#fraw = open('http://hasno.info/feed/atom.xml') { |f| f.readlines }
13fraw = open( test_path ) { |f| f.readlines }
14ds = fraw.join('')
15xpath_xpr = "/feed/entry"
16
17doc = hpd = rxd = lxd = nil
18fxn = hpn = rxn = lxn = nil
19fxs = hps = rxs = lxs = nil
20
21Benchmark.bm(15) do |x|
22  x.report("fastxml.new") { doc = FastXml::Doc.new( ds ) }
23  x.report("fastxml.to_s") { fxs = doc.to_s }
24  x.report("fastxml.search") { fxn = doc.search( xpath_xpr ) }
25  puts ""
26  x.report("hpricot.new") { hpd = Hpricot( ds ) }
27  x.report("hpricot.to_s") { hps = hpd.to_s }
28  x.report("hpricot.search") { hpn = hpd.search( xpath_xpr ) }
29  puts ""
30  x.report("libxml.new") { lxd = XML::Document.file( test_path ) }
31  x.report("libxml.to_s") { lxs = lxd.to_s }
32  x.report("libxml.search") { lxn = lxd.find( xpath_xpr )}
33  puts ""
34  x.report("REXML.new") { rxd = REXML::Document.new( ds ) }
35  x.report("REXML.to_s") { rxs = rxd.to_s }
36  x.report("REXML.xpath") { rxn = REXML::XPath.match( rxd, xpath_xpr ) }
37end
38
39puts "\noutput matching\n"
40puts "fastxml vs orig: %s\n" % (fxs && ds && (fxs == ds))
41puts "hpricot vs orig: %s\n" % (hps && ds && (hps == ds))
42puts "  REXML vs orig: %s\n" % (rxs && ds && (rxs == ds))
43puts " fastxml vs libxml: %s\n" % (fxs && lxs && (fxs == lxs))
44puts "fastxml vs hpricot: %s\n" % (fxs && hps && (fxs == hps))
45puts "  fastxml vs REXML: %s\n" % (fxs && rxs && (fxs == rxs))
46
47puts "\nxpath expression: #{xpath_xpr}\n"
48puts "fastxml nodes: %d" % fxn.length
49puts " libxml nodes: %d" % lxn.length
50puts "hpricot nodes: %d" % hpn.length
51puts "  REXML nodes: %d" % rxn.length
Note: See TracBrowser for help on using the browser.