benchmark

This commit is contained in:
Kyle Maxwell 2009-01-15 16:06:59 -08:00
parent f3aca8f9a3
commit 935db4440d
1 changed files with 51 additions and 0 deletions

51
test/yelp-benchmark.rb Normal file
View File

@ -0,0 +1,51 @@
require "rubygems"
require "nokogiri"
require "hpricot"
require "dexterous"
require "benchmark"
require "pp"
def noko
parse Nokogiri.Hpricot(File.open("yelp.html"))
end
def hpri
parse Hpricot(File.open("yelp.html"))
end
def parse(doc)
out = {}
out["name"] = (doc / "h1").first.inner_text
out["phone"] = (doc / "#bizPhone").first.inner_text
out["address"] = (doc / "address").first.inner_text
out["reviews"] = (doc / ".nonfavoriteReview").map do |node|
review = {}
review["date"] = (node / ".ieSucks .smaller").first.inner_text
review["user_name"] = (node / ".reviewer_info a").first.inner_text
review["comment"] = (node / ".review_comment").first.inner_text
review
end
end
def dext
dex = Dexterous.new({
"name" => "h1",
"phone" => "#bizPhone",
"address" => "address",
"reviews(.nonfavoriteReview)" => [
{
"date" => ".ieSucks .smaller",
"user_name" => ".reviewer_info a",
"comment" => ".review_comment"
}
]
})
dex.parse(:file => "yelp.html")
end
Benchmark.bm do |x|
x.report("nokogiri: ") { 3.times { noko } }
x.report("hpricot: ") { 3.times { hpri } }
x.report("dexterous: ") { 3.times { dext } }
end