mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Improve site benchmarks
This commit is contained in:
parent
23f69efb39
commit
051fa343d0
1 changed files with 80 additions and 42 deletions
|
@ -27,6 +27,7 @@ import (
|
||||||
type siteBuildingBenchmarkConfig struct {
|
type siteBuildingBenchmarkConfig struct {
|
||||||
Frontmatter string
|
Frontmatter string
|
||||||
NumPages int
|
NumPages int
|
||||||
|
NumLangs int
|
||||||
RootSections int
|
RootSections int
|
||||||
Render bool
|
Render bool
|
||||||
Shortcodes bool
|
Shortcodes bool
|
||||||
|
@ -39,6 +40,8 @@ func (s siteBuildingBenchmarkConfig) String() string {
|
||||||
// To make it a short as possible, we only shows bools when enabled and ints when >= 0 (RootSections > 1)
|
// To make it a short as possible, we only shows bools when enabled and ints when >= 0 (RootSections > 1)
|
||||||
sep := ","
|
sep := ","
|
||||||
id := s.Frontmatter + sep
|
id := s.Frontmatter + sep
|
||||||
|
id += fmt.Sprintf("num_langs=%d%s", s.NumLangs, sep)
|
||||||
|
|
||||||
if s.RootSections > 1 {
|
if s.RootSections > 1 {
|
||||||
id += fmt.Sprintf("num_root_sections=%d%s", s.RootSections, sep)
|
id += fmt.Sprintf("num_root_sections=%d%s", s.RootSections, sep)
|
||||||
}
|
}
|
||||||
|
@ -61,9 +64,10 @@ func (s siteBuildingBenchmarkConfig) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings.TrimSuffix(id, sep)
|
return strings.TrimSuffix(id, sep)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var someLangs = []string{"en", "fr", "nn"}
|
||||||
|
|
||||||
func BenchmarkSiteBuilding(b *testing.B) {
|
func BenchmarkSiteBuilding(b *testing.B) {
|
||||||
var (
|
var (
|
||||||
// The below represents the full matrix of benchmarks. Big!
|
// The below represents the full matrix of benchmarks. Big!
|
||||||
|
@ -74,6 +78,7 @@ func BenchmarkSiteBuilding(b *testing.B) {
|
||||||
allNumPages = []int{1, 10, 100, 500, 1000, 5000, 10000}
|
allNumPages = []int{1, 10, 100, 500, 1000, 5000, 10000}
|
||||||
allDoRender = []bool{false, true}
|
allDoRender = []bool{false, true}
|
||||||
allDoShortCodes = []bool{false, true}
|
allDoShortCodes = []bool{false, true}
|
||||||
|
allNumLangs = []int{1, 3}
|
||||||
)
|
)
|
||||||
|
|
||||||
var runDefault bool
|
var runDefault bool
|
||||||
|
@ -99,6 +104,8 @@ func BenchmarkSiteBuilding(b *testing.B) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var conf siteBuildingBenchmarkConfig
|
var conf siteBuildingBenchmarkConfig
|
||||||
|
for _, numLangs := range allNumLangs {
|
||||||
|
conf.NumLangs = numLangs
|
||||||
for _, frontmatter := range allFrontmatters {
|
for _, frontmatter := range allFrontmatters {
|
||||||
conf.Frontmatter = frontmatter
|
conf.Frontmatter = frontmatter
|
||||||
for _, rootSections := range allNumRootSections {
|
for _, rootSections := range allNumRootSections {
|
||||||
|
@ -121,6 +128,7 @@ func BenchmarkSiteBuilding(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func doBenchMarkSiteBuilding(conf siteBuildingBenchmarkConfig, b *testing.B) {
|
func doBenchMarkSiteBuilding(conf siteBuildingBenchmarkConfig, b *testing.B) {
|
||||||
|
@ -199,11 +207,29 @@ baseURL = "http://example.com/blog"
|
||||||
paginate = 10
|
paginate = 10
|
||||||
defaultContentLanguage = "en"
|
defaultContentLanguage = "en"
|
||||||
|
|
||||||
|
[languages]
|
||||||
|
%s
|
||||||
|
|
||||||
[Taxonomies]
|
[Taxonomies]
|
||||||
tag = "tags"
|
tag = "tags"
|
||||||
category = "categories"
|
category = "categories"
|
||||||
`
|
`
|
||||||
|
|
||||||
|
langConfigTemplate := `
|
||||||
|
[languages.%s]
|
||||||
|
languageName = "Lang %s"
|
||||||
|
weight = %d
|
||||||
|
`
|
||||||
|
|
||||||
|
langConfig := ""
|
||||||
|
|
||||||
|
for i := 0; i < cfg.NumLangs; i++ {
|
||||||
|
langCode := someLangs[i]
|
||||||
|
langConfig += fmt.Sprintf(langConfigTemplate, langCode, langCode, i+1)
|
||||||
|
}
|
||||||
|
|
||||||
|
siteConfig = fmt.Sprintf(siteConfig, langConfig)
|
||||||
|
|
||||||
numTags := cfg.NumTags
|
numTags := cfg.NumTags
|
||||||
|
|
||||||
if cfg.TagsPerPage > numTags {
|
if cfg.TagsPerPage > numTags {
|
||||||
|
@ -248,7 +274,12 @@ category = "categories"
|
||||||
|
|
||||||
fs := th.Fs
|
fs := th.Fs
|
||||||
|
|
||||||
pagesPerSection := cfg.NumPages / cfg.RootSections
|
pagesPerSection := cfg.NumPages / cfg.RootSections / cfg.NumLangs
|
||||||
|
for li := 0; li < cfg.NumLangs; li++ {
|
||||||
|
fileLangCodeID := ""
|
||||||
|
if li > 0 {
|
||||||
|
fileLangCodeID = "." + someLangs[li] + "."
|
||||||
|
}
|
||||||
|
|
||||||
for i := 0; i < cfg.RootSections; i++ {
|
for i := 0; i < cfg.RootSections; i++ {
|
||||||
for j := 0; j < pagesPerSection; j++ {
|
for j := 0; j < pagesPerSection; j++ {
|
||||||
|
@ -278,7 +309,14 @@ category = "categories"
|
||||||
|
|
||||||
content := fmt.Sprintf(pageTemplate, fmt.Sprintf("Title%d_%d", i, j), tagsStr, contentPagesContent[rand.Intn(3)])
|
content := fmt.Sprintf(pageTemplate, fmt.Sprintf("Title%d_%d", i, j), tagsStr, contentPagesContent[rand.Intn(3)])
|
||||||
|
|
||||||
writeSource(b, fs, filepath.Join("content", fmt.Sprintf("sect%d", i), fmt.Sprintf("page%d.md", j)), content)
|
contentFilename := fmt.Sprintf("page%d%s.md", j, fileLangCodeID)
|
||||||
|
|
||||||
|
writeSource(b, fs, filepath.Join("content", fmt.Sprintf("sect%d", i), contentFilename), content)
|
||||||
|
}
|
||||||
|
|
||||||
|
content := fmt.Sprintf(pageTemplate, fmt.Sprintf("Section %d", i), "[]", contentPagesContent[rand.Intn(3)])
|
||||||
|
indexContentFilename := fmt.Sprintf("_index%s.md", fileLangCodeID)
|
||||||
|
writeSource(b, fs, filepath.Join("content", fmt.Sprintf("sect%d", i), indexContentFilename), content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue