mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
9af47f07d3
50% speedup. Fix #91 to run the benchmark: go test -test.run=NONE -bench=".*" -test.benchmem=true ./transform/ > new.txt to compare the results: /usr/local/go/misc/benchcmp baseline.txt new.txt Speedup and memory improvements benchmark old ns/op new ns/op delta BenchmarkChain 101219 50453 -50.15% BenchmarkTransform 51625 45531 -11.80% benchmark old allocs new allocs delta BenchmarkChain 222 103 -53.60% BenchmarkTransform 135 106 -21.48% benchmark old bytes new bytes delta BenchmarkChain 23919 10998 -54.02% BenchmarkTransform 11858 10665 -10.06%
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package transform
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestChainZeroTransformers(t *testing.T) {
|
|
tr := NewChain()
|
|
in := new(bytes.Buffer)
|
|
out := new(bytes.Buffer)
|
|
if err := tr.Apply(in, out); err != nil {
|
|
t.Errorf("A zero transformer chain returned an error.")
|
|
}
|
|
}
|
|
|
|
func TestChainOneTransformer(t *testing.T) {
|
|
absURL, _ := AbsURL("http://base")
|
|
tr := NewChain(absURL...)
|
|
apply(t.Errorf, tr, abs_url_tests)
|
|
}
|
|
|
|
const H5_JS_CONTENT_ABS_URL_WITH_NAV = "<!DOCTYPE html><html><head><script src=\"/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=\"/foobar\">foobar</a>. Follow up</article></body></html>"
|
|
|
|
const CORRECT_OUTPUT_SRC_HREF_WITH_NAV = "<!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\" class=\"active\"></li></ul></nav><article>content <a href=\"http://two/foobar\">foobar</a>. Follow up</article></body></html>"
|
|
|
|
var two_chain_tests = []test{
|
|
{H5_JS_CONTENT_ABS_URL_WITH_NAV, CORRECT_OUTPUT_SRC_HREF_WITH_NAV},
|
|
}
|
|
|
|
func TestChainTwoTransformer(t *testing.T) {
|
|
absURL, _ := AbsURL("http://two")
|
|
nav := NavActive("section_1", "hugo-nav")
|
|
tr := NewChain(append(absURL, nav...)...)
|
|
apply(t.Errorf, tr, two_chain_tests)
|
|
}
|
|
|
|
func BenchmarkChain(b *testing.B) {
|
|
|
|
absURL, _ := AbsURL("http://two")
|
|
nav := NavActive("section_1", "hugo-nav")
|
|
tr := NewChain(append(absURL, nav...)...)
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
apply(b.Errorf, tr, two_chain_tests)
|
|
}
|
|
}
|