Skip to content

Commit

Permalink
Find with descendant selector without html tree
Browse files Browse the repository at this point in the history
  • Loading branch information
ypconstante committed Feb 9, 2024
1 parent b7bc377 commit 8deb26e
Showing 1 changed file with 72 additions and 13 deletions.
85 changes: 72 additions & 13 deletions benchs/finder.exs
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
tag =
case System.cmd("git", ["describe", "--tags"]) do
{reference, 0} ->
String.trim_trailing(reference)

{error, _other} ->
IO.puts("cannot get human readable name from git: #{inspect(error)}")
"unknown"
end
tag = "main"

IO.puts("tag in use for this benchmark is: #{tag}")

Expand All @@ -26,10 +18,8 @@ inputs = %{

Benchee.run(
%{
"class" => fn doc -> Floki.find(doc, ".class-mw-redirect") end,
"class multiple" => fn doc -> Floki.find(doc, ".class-mw-redirect, .reference") end,
"tag name (type)" => fn doc -> Floki.find(doc, "a") end,
"id" => fn doc -> Floki.find(doc, "#cite_note-15") end
"tag name (type)" => fn doc -> Floki.find(doc, "div") end,
"descendant selector" => fn doc -> Floki.find(doc, "div li") end
},
time: 10,
inputs: inputs,
Expand All @@ -52,3 +42,72 @@ if Enum.count(results) > 1 and function_exported?(Benchee, :report, 1) do

IO.puts("open the HTML version in: #{html_path}")
end

"""
##### With input big #####
Name ips average deviation median 99th %
tag name (type) (main) 180.89 5.53 ms ±13.71% 5.31 ms 7.45 ms
descendant selector (pr) 174.35 5.74 ms ±12.45% 5.46 ms 7.80 ms
tag name (type) (pr) 165.87 6.03 ms ±22.14% 5.33 ms 9.34 ms
descendant selector (main) 9.31 107.46 ms ±10.00% 103.95 ms 128.76 ms
Comparison:
tag name (type) (main) 180.89
descendant selector (pr) 174.35 - 1.04x slower +0.21 ms
tag name (type) (pr) 165.87 - 1.09x slower +0.50 ms
descendant selector (main) 9.31 - 19.44x slower +101.93 ms
Memory usage statistics:
Name Memory usage
tag name (type) (main) 2.13 MB
descendant selector (pr) 2.15 MB - 1.01x memory usage +0.0169 MB
tag name (type) (pr) 2.13 MB - 1.00x memory usage +0 MB
descendant selector (main) 37.71 MB - 17.71x memory usage +35.58 MB
**All measurements for memory usage were the same**
##### With input medium #####
Name ips average deviation median 99th %
tag name (type) (main) 530.53 1.88 ms ±12.97% 1.78 ms 2.69 ms
tag name (type) (pr) 528.31 1.89 ms ±12.20% 1.80 ms 2.53 ms
descendant selector (pr) 501.53 1.99 ms ±14.38% 1.87 ms 2.93 ms
descendant selector (main) 32.82 30.47 ms ±10.10% 29.76 ms 41.06 ms
Comparison:
tag name (type) (main) 530.53
tag name (type) (pr) 528.31 - 1.00x slower +0.00791 ms
descendant selector (pr) 501.53 - 1.06x slower +0.109 ms
descendant selector (main) 32.82 - 16.16x slower +28.58 ms
Memory usage statistics:
Name Memory usage
tag name (type) (main) 719.06 KB
tag name (type) (pr) 719.06 KB - 1.00x memory usage +0 KB
descendant selector (pr) 757.27 KB - 1.05x memory usage +38.20 KB
descendant selector (main) 13525.02 KB - 18.81x memory usage +12805.95 KB
**All measurements for memory usage were the same**
##### With input small #####
Name ips average deviation median 99th %
tag name (type) (pr) 2.75 K 364.01 μs ±11.26% 348.92 μs 547.66 μs
descendant selector (pr) 2.73 K 366.66 μs ±9.09% 356.10 μs 540.14 μs
tag name (type) (main) 2.64 K 379.24 μs ±15.32% 361.02 μs 601.85 μs
descendant selector (main) 0.22 K 4469.53 μs ±16.95% 4205.87 μs 7130.13 μs
Comparison:
tag name (type) (pr) 2.75 K
descendant selector (pr) 2.73 K - 1.01x slower +2.65 μs
tag name (type) (main) 2.64 K - 1.04x slower +15.23 μs
descendant selector (main) 0.22 K - 12.28x slower +4105.52 μs
Memory usage statistics:
Name Memory usage
tag name (type) (pr) 148.43 KB
descendant selector (pr) 149.43 KB - 1.01x memory usage +1 KB
tag name (type) (main) 148.43 KB - 1.00x memory usage +0 KB
descendant selector (main) 2492.95 KB - 16.80x memory usage +2344.52 KB
"""

0 comments on commit 8deb26e

Please sign in to comment.