aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/PuerkitoBio/goquery/bench_iteration_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/PuerkitoBio/goquery/bench_iteration_test.go')
-rw-r--r--vendor/github.com/PuerkitoBio/goquery/bench_iteration_test.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/vendor/github.com/PuerkitoBio/goquery/bench_iteration_test.go b/vendor/github.com/PuerkitoBio/goquery/bench_iteration_test.go
new file mode 100644
index 00000000..39445b0a
--- /dev/null
+++ b/vendor/github.com/PuerkitoBio/goquery/bench_iteration_test.go
@@ -0,0 +1,68 @@
+package goquery
+
+import (
+ "testing"
+)
+
+func BenchmarkEach(b *testing.B) {
+ var tmp, n int
+
+ b.StopTimer()
+ sel := DocW().Find("td")
+ f := func(i int, s *Selection) {
+ tmp++
+ }
+ b.StartTimer()
+ for i := 0; i < b.N; i++ {
+ sel.Each(f)
+ if n == 0 {
+ n = tmp
+ }
+ }
+ if n != 59 {
+ b.Fatalf("want 59, got %d", n)
+ }
+}
+
+func BenchmarkMap(b *testing.B) {
+ var tmp, n int
+
+ b.StopTimer()
+ sel := DocW().Find("td")
+ f := func(i int, s *Selection) string {
+ tmp++
+ return string(tmp)
+ }
+ b.StartTimer()
+ for i := 0; i < b.N; i++ {
+ sel.Map(f)
+ if n == 0 {
+ n = tmp
+ }
+ }
+ if n != 59 {
+ b.Fatalf("want 59, got %d", n)
+ }
+}
+
+func BenchmarkEachWithBreak(b *testing.B) {
+ var tmp, n int
+
+ b.StopTimer()
+ sel := DocW().Find("td")
+ f := func(i int, s *Selection) bool {
+ tmp++
+ return tmp < 10
+ }
+ b.StartTimer()
+ for i := 0; i < b.N; i++ {
+ tmp = 0
+ sel.EachWithBreak(f)
+ if n == 0 {
+ n = tmp
+ }
+ }
+ if n != 10 {
+ b.Fatalf("want 10, got %d", n)
+ }
+}