#!/usr/bin/env ruby require 'rubygems' require 'open-uri' require 'hpricot' require 'nokogiri' require 'benchmark' uri = URI.parse('http://static.bezurk.com/fragments/wikitravel/sin.xml') content = uri.read N = 1000 Benchmark.bm do |x| x.report('hpricot:doc') do N.times do Hpricot.XML(content) end end x.report('nokogiri:doc') do N.times do Nokogiri::XML(content) end end end Benchmark.bm do |x| x.report('hpricot:xpath') do N.times do doc = Hpricot.XML(content) info = doc.search('//location/info').first.inner_text url = doc.search('//location/refUrl').first.inner_text end end x.report('nokogiri:xpath') do N.times do doc = Nokogiri::XML(content) info = doc.xpath('//location/info').first.inner_text url = doc.xpath('//location/refUrl').first.inner_text end end end Benchmark.bm do |x| x.report('hpricot:css') do N.times do doc = Hpricot.XML(content) info = doc.search('location info').first.inner_text url = doc.search('location refUrl').first.inner_text end end x.report('nokogiri:css') do N.times do doc = Nokogiri::XML(content) info = doc.search('location info').first.inner_text url = doc.search('location refUrl').first.inner_text end end end