Sha256: 5225a7f9a39c93931ac93fda259a90789e999084abd8fe401ced3db1c45b108d

Contents?: true

Size: 1.54 KB

Versions: 40

Compression:

Stored size: 1.54 KB

Contents

#!/usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'hpricot'
require 'nokogiri'
require 'benchmark'

content = File.read("test/files/boingboing.html")

N = 100

unless Gem.loaded_specs['hpricot'].version > Gem::Version.new('0.6.161')
  abort "** Use higher than Hpricot 0.6.161!"
end

puts "Hpricot #{Gem.loaded_specs['hpricot'].version} vs. Nokogiri #{Gem.loaded_specs['nokogiri'].version}"
hdoc = Hpricot(content)
ndoc = Nokogiri.Hpricot(content)

Benchmark.bm do |x|
  x.report('hpricot:doc') do
    N.times do
      Hpricot(content)
    end
  end

  x.report('nokogiri:doc') do
    N.times do
      Nokogiri.Hpricot(content)
    end
  end
end

Benchmark.bm do |x|
  x.report('hpricot:xpath') do
    N.times do
      info = hdoc.search("//a[@name='027906']").first.inner_text
      url = hdoc.search("h3[text()='College kids reportedly taking more smart drugs']").first.inner_text
    end
  end

  x.report('nokogiri:xpath') do
    N.times do
      info = ndoc.search("//a[@name='027906']").first.inner_text
      url = ndoc.search("h3[text()='College kids reportedly taking more smart drugs']").first.inner_text
    end
  end
end

Benchmark.bm do |x|
  x.report('hpricot:css') do
    N.times do
      info = hdoc.search('form input[@checked]').first
      url = hdoc.search('td spacer').first.inner_text
    end
  end

  x.report('nokogiri:css') do
    N.times do
      info = ndoc.search('form input[@checked]').first
      url = ndoc.search('td spacer').first.inner_text
    end
  end
end

Version data entries

40 entries across 40 versions & 6 rubygems

Version Path
webtranslateit-hpricot-0.9.0 test/nokogiri-bench.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/hpricot-0.8.6/test/nokogiri-bench.rb
resque-pool-0.3.0 vendor/bundle/ruby/1.8/gems/hpricot-0.8.6/test/nokogiri-bench.rb
resque-pool-0.3.0.beta.2 vendor/bundle/ruby/1.8/gems/hpricot-0.8.6/test/nokogiri-bench.rb
hpricot-0.8.6 test/nokogiri-bench.rb
hpricot-0.8.6-i386-mswin32 test/nokogiri-bench.rb
hpricot-0.8.6-java test/nokogiri-bench.rb
hpricot-0.8.5-i386-mswin32 test/nokogiri-bench.rb
hpricot-0.8.5-java test/nokogiri-bench.rb
hpricot-0.8.5 test/nokogiri-bench.rb
hpricot-0.8.4 test/nokogiri-bench.rb
hpricot-0.8.4-i386-mswin32 test/nokogiri-bench.rb
hpricot-0.8.4-java test/nokogiri-bench.rb
thbar-hpricot-0.8.3.1 test/nokogiri-bench.rb
hpricot-0.8.3-i386-mswin32 test/nokogiri-bench.rb
hpricot-0.8.3-java test/nokogiri-bench.rb
hpricot-0.8.3 test/nokogiri-bench.rb
refinerycms-0.9.6.34 vendor/plugins/hpricot/test/nokogiri-bench.rb
refinerycms-0.9.6.33 vendor/plugins/hpricot/test/nokogiri-bench.rb
refinerycms-0.9.6.32 vendor/plugins/hpricot/test/nokogiri-bench.rb