-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollection_test.go
51 lines (45 loc) · 1023 Bytes
/
collection_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package gohtml
import (
"strings"
"testing"
)
func TestLength(t *testing.T) {
doc, _ := Parse(strings.NewReader(test_html))
collection := doc.All()
expect := 17
actual := collection.Length()
if actual != expect {
t.Errorf("\ngot : %v, want: %v\n", actual, expect)
}
}
func doNothing(*Element) {}
func BenchmarkFor(b *testing.B) {
doc, _ := Parse(strings.NewReader(test_html))
collection := doc.All()
length := collection.Length()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for i := 0; i < length; i++ {
doNothing(collection.Get(i))
}
}
}
func BenchmarkEnumerator(b *testing.B) {
doc, _ := Parse(strings.NewReader(test_html))
collection := doc.All()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for v := range collection.Enumerator() {
doNothing(v)
}
}
}
func BenchmarkForEach(b *testing.B) {
doc, _ := Parse(strings.NewReader(test_html))
collection := doc.All()
fn := func(v *Element, i int, a Collection) {}
b.ResetTimer()
for i := 0; i < b.N; i++ {
collection.ForEach(fn)
}
}