summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-05-30 18:10:48 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-05-30 18:10:48 +0300
commit2342df4d2dcc2f253865e317c1026c5cb673fa54 (patch)
tree6c894c43d18cb90016f12bceaacecd80e28082dc /hugolib
parent828427ef522e8c259eea520e76a1e3655b801b13 (diff)
hugolib: Add TOML/YAML switch to benchmark
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/site_benchmark_test.go57
1 files changed, 41 insertions, 16 deletions
diff --git a/hugolib/site_benchmark_test.go b/hugolib/site_benchmark_test.go
index a22f48654..e6df9f709 100644
--- a/hugolib/site_benchmark_test.go
+++ b/hugolib/site_benchmark_test.go
@@ -24,6 +24,7 @@ import (
)
type siteBuildingBenchmarkConfig struct {
+ Frontmatter string
NumPages int
RootSections int
Render bool
@@ -32,22 +33,25 @@ type siteBuildingBenchmarkConfig struct {
}
func (s siteBuildingBenchmarkConfig) String() string {
- return fmt.Sprintf("num_root_sections=%d|num_pages=%d|tags_per_page=%d|shortcodes=%t|render=%t", s.RootSections, s.NumPages, s.TagsPerPage, s.Shortcodes, s.Render)
+ return fmt.Sprintf("frontmatter=%s|num_root_sections=%d|num_pages=%d|tags_per_page=%d|shortcodes=%t|render=%t", s.Frontmatter, s.RootSections, s.NumPages, s.TagsPerPage, s.Shortcodes, s.Render)
}
func BenchmarkSiteBuilding(b *testing.B) {
var conf siteBuildingBenchmarkConfig
- for _, rootSections := range []int{1, 5} {
- conf.RootSections = rootSections
- for _, tagsPerPage := range []int{0, 1, 5, 20} {
- conf.TagsPerPage = tagsPerPage
- for _, numPages := range []int{10, 100, 500, 1000, 5000} {
- conf.NumPages = numPages
- for _, render := range []bool{false, true} {
- conf.Render = render
- for _, shortcodes := range []bool{false, true} {
- conf.Shortcodes = shortcodes
- doBenchMarkSiteBuilding(conf, b)
+ for _, frontmatter := range []string{"YAML", "TOML"} {
+ conf.Frontmatter = frontmatter
+ for _, rootSections := range []int{1, 5} {
+ conf.RootSections = rootSections
+ for _, tagsPerPage := range []int{0, 1, 5, 20} {
+ conf.TagsPerPage = tagsPerPage
+ for _, numPages := range []int{10, 100, 500, 1000, 5000} {
+ conf.NumPages = numPages
+ for _, render := range []bool{false, true} {
+ conf.Render = render
+ for _, shortcodes := range []bool{false, true} {
+ conf.Shortcodes = shortcodes
+ doBenchMarkSiteBuilding(conf, b)
+ }
}
}
}
@@ -108,7 +112,7 @@ Unicode is supported. ☺
`
- pageTemplate := `+++
+ pageTemplateTOML := `+++
title = "%s"
tags = %s
+++
@@ -116,6 +120,15 @@ tags = %s
`
+ pageTemplateYAML := `---
+title: "%s"
+tags:
+%s
+---
+%s
+
+`
+
siteConfig := `
baseURL = "http://example.com/blog"
@@ -129,6 +142,7 @@ category = "categories"
var (
contentPagesContent [3]string
tags = make([]string, cfg.TagsPerPage)
+ pageTemplate string
)
tagOffset := rand.Intn(10)
@@ -137,9 +151,20 @@ category = "categories"
tags[i] = fmt.Sprintf("Hugo %d", i+tagOffset)
}
- tagsStr := "[]"
- if cfg.TagsPerPage > 0 {
- tagsStr = strings.Replace(fmt.Sprintf("%q", tags[0:cfg.TagsPerPage]), " ", ", ", -1)
+ var tagsStr string
+
+ if cfg.Frontmatter == "TOML" {
+ pageTemplate = pageTemplateTOML
+ tagsStr = "[]"
+ if cfg.TagsPerPage > 0 {
+ tagsStr = strings.Replace(fmt.Sprintf("%q", tags[0:cfg.TagsPerPage]), " ", ", ", -1)
+ }
+ } else {
+ // YAML
+ pageTemplate = pageTemplateYAML
+ for _, tag := range tags {
+ tagsStr += "\n- " + tag
+ }
}
if cfg.Shortcodes {