From 69bd580cd4512de32fd9b1766a676b30a5888a6a Mon Sep 17 00:00:00 2001 From: Martin Angers Date: Wed, 12 Sep 2012 11:29:23 -0400 Subject: [PATCH] add benchmarks for Parent...(), Parents...() and Siblings...() --- bench_traversal_test.go | 166 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/bench_traversal_test.go b/bench_traversal_test.go index 23daa11..4df66d8 100644 --- a/bench_traversal_test.go +++ b/bench_traversal_test.go @@ -164,3 +164,169 @@ func BenchmarkParentFiltered(b *testing.B) { } b.Logf("ParentFiltered=%d", n) } + +func BenchmarkParents(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Root.Find("th a") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.Parents().Length() + } else { + sel.Parents() + } + } + b.Logf("Parents=%d", n) +} + +func BenchmarkParentsFiltered(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Root.Find("th a") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ParentsFiltered("tr").Length() + } else { + sel.ParentsFiltered("tr") + } + } + b.Logf("ParentsFiltered=%d", n) +} + +func BenchmarkParentsUntil(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Root.Find("th a") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ParentsUntil("table").Length() + } else { + sel.ParentsUntil("table") + } + } + b.Logf("ParentsUntil=%d", n) +} + +func BenchmarkParentsUntilSelection(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Root.Find("th a") + sel2 := DocW().Root.Find("#content") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ParentsUntilSelection(sel2).Length() + } else { + sel.ParentsUntilSelection(sel2) + } + } + b.Logf("ParentsUntilSelection=%d", n) +} + +func BenchmarkParentsUntilNodes(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Root.Find("th a") + sel2 := DocW().Root.Find("#content") + nodes := sel2.Nodes + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ParentsUntilNodes(nodes...).Length() + } else { + sel.ParentsUntilNodes(nodes...) + } + } + b.Logf("ParentsUntilNodes=%d", n) +} + +func BenchmarkParentsFilteredUntil(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Root.Find(".toclevel-1 a") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ParentsFilteredUntil(":nth-child(1)", "ul").Length() + } else { + sel.ParentsFilteredUntil(":nth-child(1)", "ul") + } + } + b.Logf("ParentsFilteredUntil=%d", n) +} + +func BenchmarkParentsFilteredUntilSelection(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Root.Find(".toclevel-1 a") + sel2 := DocW().Root.Find("ul") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ParentsFilteredUntilSelection(":nth-child(1)", sel2).Length() + } else { + sel.ParentsFilteredUntilSelection(":nth-child(1)", sel2) + } + } + b.Logf("ParentsFilteredUntilSelection=%d", n) +} + +func BenchmarkParentsFilteredUntilNodes(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Root.Find(".toclevel-1 a") + sel2 := DocW().Root.Find("ul") + nodes := sel2.Nodes + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.ParentsFilteredUntilNodes(":nth-child(1)", nodes...).Length() + } else { + sel.ParentsFilteredUntilNodes(":nth-child(1)", nodes...) + } + } + b.Logf("ParentsFilteredUntilNodes=%d", n) +} + +func BenchmarkSiblings(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Root.Find("ul li:nth-child(1)") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.Siblings().Length() + } else { + sel.Siblings() + } + } + b.Logf("Siblings=%d", n) +} + +func BenchmarkSiblingsFiltered(b *testing.B) { + var n int + + b.StopTimer() + sel := DocW().Root.Find("ul li:nth-child(1)") + b.StartTimer() + for i := 0; i < b.N; i++ { + if n == 0 { + n = sel.SiblingsFiltered("[class]").Length() + } else { + sel.SiblingsFiltered("[class]") + } + } + b.Logf("SiblingsFiltered=%d", n) +}