Skip to content

Commit

Permalink
Add a TOML front matter benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Jul 27, 2021
1 parent efa5760 commit 7e13057
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions hugolib/site_benchmark_new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type siteBenchmarkTestcase struct {

func getBenchmarkSiteDeepContent(b testing.TB) *sitesBuilder {
pageContent := func(size int) string {
return getBenchmarkTestDataPageContentForMarkdown(size, "", benchmarkMarkdownSnippets)
return getBenchmarkTestDataPageContentForMarkdown(size, false, "", benchmarkMarkdownSnippets)
}

sb := newTestSitesBuilder(b).WithConfigFile("toml", `
Expand Down Expand Up @@ -85,18 +85,31 @@ contentDir="content/sv"
return sb
}

func getBenchmarkTestDataPageContentForMarkdown(size int, category, markdown string) string {
func getBenchmarkTestDataPageContentForMarkdown(size int, toml bool, category, markdown string) string {
base := `---
title: "My Page"
%s
---
My page content.
`
if toml {
base = `+++
title="My Page"
%s
+++
My page content.
`

}

var categoryKey string
if category != "" {
categoryKey = fmt.Sprintf("categories: [%s]", category)
if toml {
categoryKey = fmt.Sprintf("categories=[%s]", category)
}
}
base = fmt.Sprintf(base, categoryKey)

Expand All @@ -119,11 +132,11 @@ See my [About](/about/) page for details.

func getBenchmarkSiteNewTestCases() []siteBenchmarkTestcase {
pageContentWithCategory := func(size int, category string) string {
return getBenchmarkTestDataPageContentForMarkdown(size, category, benchmarkMarkdownSnippets)
return getBenchmarkTestDataPageContentForMarkdown(size, false, category, benchmarkMarkdownSnippets)
}

pageContent := func(size int) string {
return getBenchmarkTestDataPageContentForMarkdown(size, "", benchmarkMarkdownSnippets)
return getBenchmarkTestDataPageContentForMarkdown(size, false, "", benchmarkMarkdownSnippets)
}

config := `
Expand Down Expand Up @@ -217,6 +230,20 @@ canonifyURLs = true
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 {
pageTemplateTemplate := `
Expand Down

0 comments on commit 7e13057

Please sign in to comment.