Skip to content

Commit

Permalink
Add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Giuseppe Pagano committed Apr 13, 2019
1 parent 9bc9c8d commit cd7dd97
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions benchmark/tree_visti_vs_xpath.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require "crystagiri"

def do_test(url : String)
Crystagiri::HTML.experimental = false
t = Time.now
doc = Crystagiri::HTML.from_url url
1..100000.times do
doc.at_tag("div")
doc.where_class("step-title") { |tag| tag }
doc.where_class("content") { |tag| tag }
doc.where_tag("span") { |tag| tag }
end
result_legacy = Time.now - t

Crystagiri::HTML.experimental = true
t = Time.now
doc = Crystagiri::HTML.from_url url
1..100000.times do
doc.at_tag("div")
doc.where_class("step-title") { |tag| tag }
doc.where_class("content") { |tag| tag }
doc.where_tag("span") { |tag| tag }
end
result_experimental = Time.now - t

[result_legacy.milliseconds, result_experimental.milliseconds]
end

test_links = [
"https://www.quirksmode.org/html5/tests/video.html",
"http://www.8164.org/the-big-table-issue/",
"https://lawsofux.com/",
"https://www.youtube.com/"
]

total_legacy = 0
total_experimental = 0

test_links.each do | link |
print "."
legacy, experimental = do_test link

total_legacy += legacy
total_experimental += experimental
print "."
end

puts "Test ran on #{test_links.size} links.\nTime with xpath method: #{total_legacy} ms.\nTime with experimental method: #{total_experimental} ms."

0 comments on commit cd7dd97

Please sign in to comment.