mirror of
https://github.com/gohugoio/hugo.git
synced 2025-05-07 11:16:26 +03:00
Improve rendering time
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%
This commit is contained in:
parent
f4cb8e1688
commit
9af47f07d3
9 changed files with 58 additions and 115 deletions
|
@ -31,25 +31,11 @@ const EXPECTED_HTML_WITH_NAV_1 = `<!DOCTYPE html><html><head></head>
|
|||
|
||||
</body></html>`
|
||||
|
||||
func TestDegenerateNoSectionSet(t *testing.T) {
|
||||
var (
|
||||
tr = new(NavActive)
|
||||
out = new(bytes.Buffer)
|
||||
)
|
||||
|
||||
if err := tr.Apply(out, strings.NewReader(HTML_WITH_NAV)); err != nil {
|
||||
t.Errorf("Unexpected error in NavActive.Apply: %s", err)
|
||||
}
|
||||
|
||||
if out.String() != HTML_WITH_NAV {
|
||||
t.Errorf("NavActive.Apply should simply pass along the buffer unmodified.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetNav(t *testing.T) {
|
||||
tr := &NavActive{Section: "section_2"}
|
||||
trs := NavActive("section_2", "hugo-nav")
|
||||
chain := NewChain(trs...)
|
||||
out := new(bytes.Buffer)
|
||||
if err := tr.Apply(out, strings.NewReader(HTML_WITH_NAV)); err != nil {
|
||||
if err := chain.Apply(out, strings.NewReader(HTML_WITH_NAV)); err != nil {
|
||||
t.Errorf("Unexpected error in Apply() for NavActive: %s", err)
|
||||
}
|
||||
|
||||
|
@ -60,11 +46,13 @@ func TestSetNav(t *testing.T) {
|
|||
}
|
||||
|
||||
func BenchmarkTransform(b *testing.B) {
|
||||
tr := NavActive("section_2", "hugo-nav")
|
||||
chain := NewChain(tr...)
|
||||
out := new(bytes.Buffer)
|
||||
for i := 0; i < b.N; i++ {
|
||||
tr := &NavActive{Section: "section_2"}
|
||||
out := new(bytes.Buffer)
|
||||
if err := tr.Apply(out, strings.NewReader(HTML_WITH_NAV)); err != nil {
|
||||
if err := chain.Apply(out, strings.NewReader(HTML_WITH_NAV)); err != nil {
|
||||
b.Errorf("Unexpected error in Apply() for NavActive: %s", err)
|
||||
}
|
||||
out.Reset()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue