Skip to content

Instantly share code, notes, and snippets.

@jgaskins
Created February 23, 2014 04:39
Show Gist options
  • Save jgaskins/9166890 to your computer and use it in GitHub Desktop.
Save jgaskins/9166890 to your computer and use it in GitHub Desktop.
Benchmarking Nokogiri, LibXML, and Ox
Parsing...
Calculating -------------------------------------
nokogiri 127 i/100ms
libxml 130 i/100ms
ox 716 i/100ms
-------------------------------------------------
nokogiri 1334.7 (±15.1%) i/s - 6604 in 5.215835s
libxml 1287.5 (±1.9%) i/s - 6500 in 5.050367s
ox 7228.3 (±3.7%) i/s - 36516 in 5.059256s
Generating...
Calculating -------------------------------------
nokogiri 175 i/100ms
libxml 626 i/100ms
ox 1439 i/100ms
-------------------------------------------------
nokogiri 1814.3 (±13.2%) i/s - 8925 in 5.041975s
libxml 6831.1 (±11.4%) i/s - 33804 in 5.073526s
ox 15972.9 (±17.4%) i/s - 77706 in 5.018197s
require 'nokogiri'
require 'libxml'
require 'ox'
require 'benchmark/ips'
xml = File.read('atom.xml')
nokogiri = Nokogiri::XML::Document.parse(xml)
libxml = LibXML::XML::Document.string(xml)
ox = Ox.parse(xml)
puts "Parsing..."
Benchmark.ips do |x|
x.report 'nokogiri' do
Nokogiri::XML::Document.parse(xml)
end
x.report 'libxml' do
LibXML::XML::Document.string(xml)
end
x.report 'ox' do
Ox.parse(xml)
end
end
puts
puts "Generating..."
Benchmark.ips do |x|
x.report 'nokogiri' do
nokogiri.to_xml(indent: 2)
end
x.report 'libxml' do
libxml.to_s
end
x.report 'ox' do
Ox.dump(ox, indent: 2)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment