rxerces 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGES.md +19 -0
- data/README.md +14 -3
- data/benchmarks/README.md +68 -0
- data/benchmarks/css_benchmark.rb +115 -0
- data/benchmarks/parse_benchmark.rb +103 -0
- data/benchmarks/run_all.rb +25 -0
- data/benchmarks/serialization_benchmark.rb +93 -0
- data/benchmarks/traversal_benchmark.rb +149 -0
- data/benchmarks/xpath_benchmark.rb +100 -0
- data/ext/rxerces/rxerces.cpp +977 -50
- data/lib/rxerces/nokogiri.rb +26 -0
- data/lib/rxerces/version.rb +1 -1
- data/rxerces.gemspec +1 -1
- data/spec/document_spec.rb +117 -0
- data/spec/node_spec.rb +408 -4
- data/spec/nodeset_spec.rb +59 -0
- data/spec/nokogiri_compatibility_spec.rb +44 -0
- data/spec/rxerces_shared.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +8 -1
- metadata.gz.sig +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'benchmark/ips'
|
|
5
|
+
require 'rxerces'
|
|
6
|
+
|
|
7
|
+
begin
|
|
8
|
+
require 'nokogiri'
|
|
9
|
+
NOKOGIRI_AVAILABLE = true
|
|
10
|
+
rescue LoadError
|
|
11
|
+
NOKOGIRI_AVAILABLE = false
|
|
12
|
+
puts "Nokogiri not available - install with: gem install nokogiri"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Sample XML for XPath queries
|
|
16
|
+
XML_DATA = begin
|
|
17
|
+
books = (1..500).map do |i|
|
|
18
|
+
category = ['fiction', 'science', 'biography', 'history'][i % 4]
|
|
19
|
+
year = 1990 + (i % 30)
|
|
20
|
+
price = 10.0 + (i % 50)
|
|
21
|
+
"<book id=\"book#{i}\" category=\"#{category}\">
|
|
22
|
+
<title lang=\"en\">Title #{i}</title>
|
|
23
|
+
<author>Author #{i}</author>
|
|
24
|
+
<year>#{year}</year>
|
|
25
|
+
<price>#{'%.2f' % price}</price>
|
|
26
|
+
</book>"
|
|
27
|
+
end
|
|
28
|
+
"<catalog>#{books.join}</catalog>"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
puts "=" * 80
|
|
32
|
+
puts "XPath Query Benchmarks"
|
|
33
|
+
puts "=" * 80
|
|
34
|
+
puts "XML Size: #{XML_DATA.bytesize} bytes"
|
|
35
|
+
puts
|
|
36
|
+
|
|
37
|
+
# Parse documents once
|
|
38
|
+
rxerces_doc = RXerces::XML::Document.parse(XML_DATA)
|
|
39
|
+
nokogiri_doc = Nokogiri::XML(XML_DATA) if NOKOGIRI_AVAILABLE
|
|
40
|
+
|
|
41
|
+
# Simple XPath queries
|
|
42
|
+
puts "Simple XPath: //book"
|
|
43
|
+
puts "-" * 80
|
|
44
|
+
|
|
45
|
+
Benchmark.ips do |x|
|
|
46
|
+
x.config(time: 5, warmup: 2)
|
|
47
|
+
|
|
48
|
+
x.report("rxerces") { rxerces_doc.xpath('//book') }
|
|
49
|
+
x.report("nokogiri") { nokogiri_doc.xpath('//book') } if NOKOGIRI_AVAILABLE
|
|
50
|
+
|
|
51
|
+
x.compare!
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
puts
|
|
55
|
+
|
|
56
|
+
# Attribute-based XPath queries
|
|
57
|
+
puts "Attribute XPath: //book[@category='fiction']"
|
|
58
|
+
puts "-" * 80
|
|
59
|
+
|
|
60
|
+
Benchmark.ips do |x|
|
|
61
|
+
x.config(time: 5, warmup: 2)
|
|
62
|
+
|
|
63
|
+
x.report("rxerces") { rxerces_doc.xpath("//book[@category='fiction']") }
|
|
64
|
+
x.report("nokogiri") { nokogiri_doc.xpath("//book[@category='fiction']") } if NOKOGIRI_AVAILABLE
|
|
65
|
+
|
|
66
|
+
x.compare!
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
puts
|
|
70
|
+
|
|
71
|
+
# Complex XPath queries
|
|
72
|
+
puts "Complex XPath: //book[year > 2000 and price < 30]/title"
|
|
73
|
+
puts "-" * 80
|
|
74
|
+
|
|
75
|
+
Benchmark.ips do |x|
|
|
76
|
+
x.config(time: 5, warmup: 2)
|
|
77
|
+
|
|
78
|
+
x.report("rxerces") { rxerces_doc.xpath('//book[year > 2000 and price < 30]/title') }
|
|
79
|
+
x.report("nokogiri") { nokogiri_doc.xpath('//book[year > 2000 and price < 30]/title') } if NOKOGIRI_AVAILABLE
|
|
80
|
+
|
|
81
|
+
x.compare!
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
puts
|
|
85
|
+
|
|
86
|
+
# at_xpath (first match)
|
|
87
|
+
puts "at_xpath: //book (first match only)"
|
|
88
|
+
puts "-" * 80
|
|
89
|
+
|
|
90
|
+
Benchmark.ips do |x|
|
|
91
|
+
x.config(time: 5, warmup: 2)
|
|
92
|
+
|
|
93
|
+
x.report("rxerces") { rxerces_doc.root.at_xpath('//book') }
|
|
94
|
+
x.report("nokogiri") { nokogiri_doc.at_xpath('//book') } if NOKOGIRI_AVAILABLE
|
|
95
|
+
|
|
96
|
+
x.compare!
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
puts
|
|
100
|
+
puts "=" * 80
|