-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Giuseppe Pagano
committed
Apr 13, 2019
1 parent
9bc9c8d
commit cd7dd97
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
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
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." |