diff --git a/benchmark/xml/parser/comparing_gems_bench.rb b/benchmark/xml/parser/comparing_gems_bench.rb new file mode 100644 index 0000000..cd4b6f7 --- /dev/null +++ b/benchmark/xml/parser/comparing_gems_bench.rb @@ -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 diff --git a/benchmark/xpath/parser/comparing_gems_bench.rb b/benchmark/xpath/parser/comparing_gems_bench.rb new file mode 100644 index 0000000..9f1837d --- /dev/null +++ b/benchmark/xpath/parser/comparing_gems_bench.rb @@ -0,0 +1,36 @@ +require_relative '../../benchmark_helper' + +require 'nokogiri' +require 'ox' +require 'rexml/document' + +xml = '10' + +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