#!/usr/bin/env ruby require 'rubygems' require 'open-uri' require 'hpricot' require 'nokogiri' require 'better-benchmark' uri = URI.parse( 'http://static.bezurk.com/fragments/wikitravel/sin.xml' ) content = uri.read puts "\nhpricot vs. nokogiri: Parsing XML" result = Benchmark.compare_realtime( :iterations => 10, :inner_iterations => 15000, :verbose => true ) { Hpricot.XML content }.with { Nokogiri::XML content } Benchmark.report_on result puts "\nhpricot vs. nokogiri: Searching with XPath" result = Benchmark.compare_realtime( :iterations => 10, :inner_iterations => 2000, :verbose => true ) { doc = Hpricot.XML(content) info = doc.search('//location/info').first.inner_text url = doc.search('//location/refUrl').first.inner_text }.with { doc = Nokogiri::XML(content) info = doc.xpath('//location/info').first.inner_text url = doc.xpath('//location/refUrl').first.inner_text } Benchmark.report_on result puts "\nhpricot vs. nokogiri: Searching with CSS" result = Benchmark.compare_realtime( :iterations => 10, :inner_iterations => 2000, :verbose => true ) { doc = Hpricot.XML(content) info = doc.search('location info').first.inner_text url = doc.search('location refUrl').first.inner_text }.with { doc = Nokogiri::XML(content) info = doc.search('location info').first.inner_text url = doc.search('location refUrl').first.inner_text } Benchmark.report_on result