benchmark
This commit is contained in:
parent
f3aca8f9a3
commit
935db4440d
|
@ -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
|
||||
|
Loading…
Reference in New Issue