mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-15 20:44:01 +02:00
Add benchmark test for StripHTML
go test -test.run=NONE -bench=".*" -test.benchmem=true ./helpers Old vs new impl (string.Replace vs string.Replacer): benchmark old ns/op new ns/op delta BenchmarkStripHTML 10210 6572 -35.63% benchmark old allocs new allocs delta BenchmarkStripHTML 6 5 -16.67% benchmark old bytes new bytes delta BenchmarkStripHTML 1456 848 -41.76%
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const tstHtmlContent = "<!DOCTYPE html><html><head><script src=\"http://two/foobar.js\"></script></head><body><nav><ul><li hugo-nav=\"section_0\"></li><li hugo-nav=\"section_1\"></li></ul></nav><article>content <a href=\"http://two/foobar\">foobar</a>. Follow up</article><p>This is some text.<br>And some more.</p></body></html>"
|
||||||
|
|
||||||
func TestStripHTML(t *testing.T) {
|
func TestStripHTML(t *testing.T) {
|
||||||
type test struct {
|
type test struct {
|
||||||
input, expected string
|
input, expected string
|
||||||
@@ -26,6 +28,13 @@ func TestStripHTML(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkStripHTML(b *testing.B) {
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
StripHTML(tstHtmlContent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestStripEmptyNav(t *testing.T) {
|
func TestStripEmptyNav(t *testing.T) {
|
||||||
cleaned := StripEmptyNav([]byte("do<nav>\n</nav>\n\nbedobedo"))
|
cleaned := StripEmptyNav([]byte("do<nav>\n</nav>\n\nbedobedo"))
|
||||||
assert.Equal(t, []byte("dobedobedo"), cleaned)
|
assert.Equal(t, []byte("dobedobedo"), cleaned)
|
||||||
|
Reference in New Issue
Block a user