Created
February 8, 2015 04:39
-
-
Save devton/40d591412bb8f32b3344 to your computer and use it in GitHub Desktop.
Basica benchmark for MetaInspector and Direct nokogiri
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# user system total real | |
# MetaInspector: 1.150000 0.040000 1.190000 (1.241086) | |
# Nokogiri #xpath: 0.010000 0.000000 0.010000 (0.011218) | |
# Nokogiri #css 0.010000 0.000000 0.010000 (0.010822) | |
# Nokogiri #search 0.010000 0.000000 0.010000 (0.010091) | |
require 'open-uri' | |
namespace :benchmarks do | |
desc 'MetaInspector vs Nokogiri' | |
task metagiri: :environment do | |
html = (1..1_000).inject("") { |t, i| t += "<a href='/page_#{i}.html'>link to page_#{i}</a>" } | |
FakeWeb.register_uri(:get, "http://example.com", body: html) | |
Benchmark.bm do |x| | |
x.report("MetaInspector:") do | |
page = MetaInspector.new('http://example.com') | |
page.links.all | |
end | |
x.report("Nokogiri #xpath:") do | |
page = Nokogiri::HTML(open('http://example.com')) | |
page.xpath('//a/@href').map { |node| node['href'] } | |
end | |
x.report("Nokogiri #css") do | |
page = Nokogiri::HTML(open('http://example.com')) | |
page.css('a').map { |node| node['href'] } | |
end | |
x.report("Nokogiri #search") do | |
page = Nokogiri::HTML(open('http://example.com')) | |
page.search('//a/@href').map { |node| node['href'] } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment