Benchmarks for comparing Oga with others.
This includes two benchmarks: one for parsing XML and one for evaluating XPath.
This commit is contained in:
parent
0b096dfe25
commit
84d6ba96c2
|
|
@ -0,0 +1,27 @@
|
||||||
|
require_relative '../../benchmark_helper'
|
||||||
|
|
||||||
|
require 'nokogiri'
|
||||||
|
require 'ox'
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
|
xml = read_big_xml
|
||||||
|
|
||||||
|
Benchmark.ips do |bench|
|
||||||
|
bench.report 'Ox' do
|
||||||
|
Ox.parse(xml)
|
||||||
|
end
|
||||||
|
|
||||||
|
bench.report 'Nokogiri' do
|
||||||
|
Nokogiri::XML(xml)
|
||||||
|
end
|
||||||
|
|
||||||
|
bench.report 'Oga' do
|
||||||
|
Oga::XML::Parser.new(xml).parse
|
||||||
|
end
|
||||||
|
|
||||||
|
bench.report 'REXML' do
|
||||||
|
REXML::Document.new(xml)
|
||||||
|
end
|
||||||
|
|
||||||
|
bench.compare!
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
require_relative '../../benchmark_helper'
|
||||||
|
|
||||||
|
require 'nokogiri'
|
||||||
|
require 'ox'
|
||||||
|
require 'rexml/document'
|
||||||
|
|
||||||
|
xml = '<root><number>10</number></root>'
|
||||||
|
|
||||||
|
ox_doc = Ox.parse(xml)
|
||||||
|
noko_doc = Nokogiri::XML(xml)
|
||||||
|
oga_doc = Oga::XML::Parser.new(xml).parse
|
||||||
|
rex_doc = REXML::Document.new(xml)
|
||||||
|
|
||||||
|
ox_exp = 'number/^Text'
|
||||||
|
xpath_exp = 'root/number/text()'
|
||||||
|
|
||||||
|
Benchmark.ips do |bench|
|
||||||
|
# Technically not XPath but it's the closest thing Ox provides.
|
||||||
|
bench.report 'Ox' do
|
||||||
|
ox_doc.locate(ox_exp)
|
||||||
|
end
|
||||||
|
|
||||||
|
bench.report 'Nokogiri' do
|
||||||
|
noko_doc.xpath(xpath_exp)
|
||||||
|
end
|
||||||
|
|
||||||
|
bench.report 'Oga' do
|
||||||
|
oga_doc.xpath(xpath_exp)
|
||||||
|
end
|
||||||
|
|
||||||
|
bench.report 'REXML' do
|
||||||
|
REXML::XPath.match(rex_doc, xpath_exp)
|
||||||
|
end
|
||||||
|
|
||||||
|
bench.compare!
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue