mirror of
https://github.com/PuerkitoBio/goquery
synced 2025-09-26 21:01:21 +08:00
43 lines
570 B
Go
43 lines
570 B
Go
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
|
|
}
|
|
}
|
|
b.Logf("Each=%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
|
|
}
|
|
}
|
|
b.Logf("Map=%d", n)
|
|
}
|