Add a TOML front matter benchmark

This commit is contained in:
Bjørn Erik Pedersen 2021-07-27 19:24:19 +02:00
parent efa5760db5
commit 7e1305710f
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F

View file

@ -35,7 +35,7 @@ type siteBenchmarkTestcase struct {
func getBenchmarkSiteDeepContent(b testing.TB) *sitesBuilder { func getBenchmarkSiteDeepContent(b testing.TB) *sitesBuilder {
pageContent := func(size int) string { pageContent := func(size int) string {
return getBenchmarkTestDataPageContentForMarkdown(size, "", benchmarkMarkdownSnippets) return getBenchmarkTestDataPageContentForMarkdown(size, false, "", benchmarkMarkdownSnippets)
} }
sb := newTestSitesBuilder(b).WithConfigFile("toml", ` sb := newTestSitesBuilder(b).WithConfigFile("toml", `
@ -85,7 +85,7 @@ contentDir="content/sv"
return sb return sb
} }
func getBenchmarkTestDataPageContentForMarkdown(size int, category, markdown string) string { func getBenchmarkTestDataPageContentForMarkdown(size int, toml bool, category, markdown string) string {
base := `--- base := `---
title: "My Page" title: "My Page"
%s %s
@ -93,10 +93,23 @@ title: "My Page"
My page content. My page content.
` `
if toml {
base = `+++
title="My Page"
%s
+++
My page content.
`
}
var categoryKey string var categoryKey string
if category != "" { if category != "" {
categoryKey = fmt.Sprintf("categories: [%s]", category) categoryKey = fmt.Sprintf("categories: [%s]", category)
if toml {
categoryKey = fmt.Sprintf("categories=[%s]", category)
}
} }
base = fmt.Sprintf(base, categoryKey) base = fmt.Sprintf(base, categoryKey)
@ -119,11 +132,11 @@ See my [About](/about/) page for details.
func getBenchmarkSiteNewTestCases() []siteBenchmarkTestcase { func getBenchmarkSiteNewTestCases() []siteBenchmarkTestcase {
pageContentWithCategory := func(size int, category string) string { pageContentWithCategory := func(size int, category string) string {
return getBenchmarkTestDataPageContentForMarkdown(size, category, benchmarkMarkdownSnippets) return getBenchmarkTestDataPageContentForMarkdown(size, false, category, benchmarkMarkdownSnippets)
} }
pageContent := func(size int) string { pageContent := func(size int) string {
return getBenchmarkTestDataPageContentForMarkdown(size, "", benchmarkMarkdownSnippets) return getBenchmarkTestDataPageContentForMarkdown(size, false, "", benchmarkMarkdownSnippets)
} }
config := ` config := `
@ -217,6 +230,20 @@ canonifyURLs = true
s.Assert(len(s.H.Sites[0].RegularPages()), qt.Equals, 30) s.Assert(len(s.H.Sites[0].RegularPages()), qt.Equals, 30)
}, },
}, },
{
"TOML front matter", func(b testing.TB) *sitesBuilder {
sb := newTestSitesBuilder(b).WithConfigFile("toml", config)
for i := 1; i <= 200; i++ {
content := getBenchmarkTestDataPageContentForMarkdown(1, true, "\"a\", \"b\", \"c\"", benchmarkMarkdownSnippets)
sb.WithContent(fmt.Sprintf("content/p%d.md", i), content)
}
return sb
},
func(s *sitesBuilder) {
},
},
{ {
"Many HTML templates", func(b testing.TB) *sitesBuilder { "Many HTML templates", func(b testing.TB) *sitesBuilder {
pageTemplateTemplate := ` pageTemplateTemplate := `