From 77c7059ff832870c3920e87a87969b815e429a8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 16 Feb 2022 13:30:53 +0100 Subject: [PATCH] markup/goldmark: Add a render hook benchmark Updates #9504 --- markup/goldmark/integration_test.go | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/markup/goldmark/integration_test.go b/markup/goldmark/integration_test.go index 387d7be6649..fd90a6824e5 100644 --- a/markup/goldmark/integration_test.go +++ b/markup/goldmark/integration_test.go @@ -14,6 +14,7 @@ package goldmark_test import ( + "fmt" "testing" "github.com/gohugoio/hugo/hugolib" @@ -59,3 +60,57 @@ foo
`) } + +func BenchmarkSiteWithRenderHooks(b *testing.B) { + files := ` +-- config.toml -- +-- layouts/_default/_markup/render-heading.html -- + + {{ .Text | safeHTML }} + # + +-- layouts/_default/_markup/render-link.html -- +{{ .Text | safeHTML }} +-- layouts/_default/single.html -- +{{ .Content }} +` + + content := ` + +## Hello1 [Test](https://example.com) + +A. + +## Hello2 [Test](https://example.com) + +B. + +## Hello3 [Test](https://example.com) + +C. + +## Hello3 [Test](https://example.com) + +D. +` + + for i := 1; i < 100; i++ { + files += fmt.Sprintf("\n-- content/posts/p%d.md --\n"+content, i+1) + } + + cfg := hugolib.IntegrationTestConfig{ + T: b, + TxtarString: files, + } + builders := make([]*hugolib.IntegrationTestBuilder, b.N) + + for i := range builders { + builders[i] = hugolib.NewIntegrationTestBuilder(cfg) + } + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + builders[i].Build() + } +}