1
0
Fork 0
miniflux/vendor/github.com/andybalholm/cascadia/benchmark_test.go
Frédéric Guillot 8ffb773f43 First commit
2017-11-19 22:01:46 -08:00

53 lines
1 KiB
Go

package cascadia
import (
"strings"
"testing"
"golang.org/x/net/html"
)
func MustParseHTML(doc string) *html.Node {
dom, err := html.Parse(strings.NewReader(doc))
if err != nil {
panic(err)
}
return dom
}
var selector = MustCompile(`div.matched`)
var doc = `<!DOCTYPE html>
<html>
<body>
<div class="matched">
<div>
<div class="matched"></div>
<div class="matched"></div>
<div class="matched"></div>
<div class="matched"></div>
<div class="matched"></div>
<div class="matched"></div>
<div class="matched"></div>
<div class="matched"></div>
<div class="matched"></div>
<div class="matched"></div>
<div class="matched"></div>
<div class="matched"></div>
<div class="matched"></div>
<div class="matched"></div>
<div class="matched"></div>
<div class="matched"></div>
</div>
</div>
</body>
</html>
`
var dom = MustParseHTML(doc)
func BenchmarkMatchAll(b *testing.B) {
var matches []*html.Node
for i := 0; i < b.N; i++ {
matches = selector.MatchAll(dom)
}
_ = matches
}