From 6c7e98359b4ecb2a9b5338b926cc17a153e354f9 Mon Sep 17 00:00:00 2001 From: Martin Angers Date: Tue, 11 Sep 2012 20:36:48 -0400 Subject: [PATCH] add benchmarks for iteration.go --- bench_iteration_test.go | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 bench_iteration_test.go diff --git a/bench_iteration_test.go b/bench_iteration_test.go new file mode 100644 index 0000000..437fba9 --- /dev/null +++ b/bench_iteration_test.go @@ -0,0 +1,42 @@ +package goquery + +import ( + "testing" +) + +func BenchmarkEach(b *testing.B) { + var tmp, n int + + b.StopTimer() + sel := DocW().Root.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 + } + } + b.Logf("Each=%d", n) +} + +func BenchmarkMap(b *testing.B) { + var tmp, n int + + b.StopTimer() + sel := DocW().Root.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 + } + } + b.Logf("Map=%d", n) +}