Skip to content

Commit c3c10f2

Browse files
committed
Simplify Site benchmarks
Now running `./benchSite.sh` should give a good baseline.
1 parent ad5ef43 commit c3c10f2

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

‎benchSite.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ GOEXE="${GOEXE-go}"
99

1010
echo "Running with BenchmarkSiteBuilding/${1}"
1111

12-
"${GOEXE}" test -run="NONE" -bench="BenchmarkSiteBuilding/${1}$" -test.benchmem=true ./hugolib -memprofile mem.prof -cpuprofile cpu.prof
12+
"${GOEXE}" test -run="NONE" -bench="BenchmarkSiteBuilding/${1}" -test.benchmem=true ./hugolib -memprofile mem.prof -cpuprofile cpu.prof

‎hugolib/site_benchmark_test.go‎

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package hugolib
1515

1616
import (
17+
"flag"
1718
"fmt"
1819
"math/rand"
1920
"path/filepath"
@@ -64,20 +65,53 @@ func (s siteBuildingBenchmarkConfig) String() string {
6465
}
6566

6667
func BenchmarkSiteBuilding(b *testing.B) {
68+
var (
69+
// The below represents the full matrix of benchmarks. Big!
70+
allFrontmatters = []string{"YAML", "TOML"}
71+
allNumRootSections = []int{1, 5}
72+
allNumTags = []int{0, 1, 10, 20, 50, 100, 500, 1000, 5000}
73+
allTagsPerPage = []int{0, 1, 5, 20, 50, 80}
74+
allNumPages = []int{1, 10, 100, 500, 1000, 5000, 10000}
75+
allDoRender = []bool{false, true}
76+
allDoShortCodes = []bool{false, true}
77+
)
78+
79+
var runDefault bool
80+
81+
visitor := func(a *flag.Flag) {
82+
if a.Name == "test.bench" && len(a.Value.String()) < 40 {
83+
// The full suite is too big, so fall back to some smaller default if no
84+
// restriction is set.
85+
runDefault = true
86+
}
87+
}
88+
89+
flag.Visit(visitor)
90+
91+
if runDefault {
92+
allFrontmatters = allFrontmatters[1:]
93+
allNumRootSections = allNumRootSections[0:2]
94+
allNumTags = allNumTags[0:2]
95+
allTagsPerPage = allTagsPerPage[2:3]
96+
allNumPages = allNumPages[2:5]
97+
allDoRender = allDoRender[1:2]
98+
allDoShortCodes = allDoShortCodes[1:2]
99+
}
100+
67101
var conf siteBuildingBenchmarkConfig
68-
for _, frontmatter := range []string{"YAML", "TOML"} {
102+
for _, frontmatter := range allFrontmatters {
69103
conf.Frontmatter = frontmatter
70-
for _, rootSections := range []int{1, 5} {
104+
for _, rootSections := range allNumRootSections {
71105
conf.RootSections = rootSections
72-
for _, numTags := range []int{0, 1, 10, 20, 50, 100, 500, 1000, 5000} {
106+
for _, numTags := range allNumTags {
73107
conf.NumTags = numTags
74-
for _, tagsPerPage := range []int{0, 1, 5, 20, 50, 80} {
108+
for _, tagsPerPage := range allTagsPerPage {
75109
conf.TagsPerPage = tagsPerPage
76-
for _, numPages := range []int{1, 10, 100, 500, 1000, 5000, 10000} {
110+
for _, numPages := range allNumPages {
77111
conf.NumPages = numPages
78-
for _, render := range []bool{false, true} {
112+
for _, render := range allDoRender {
79113
conf.Render = render
80-
for _, shortcodes := range []bool{false, true} {
114+
for _, shortcodes := range allDoShortCodes {
81115
conf.Shortcodes = shortcodes
82116
doBenchMarkSiteBuilding(conf, b)
83117
}
@@ -207,8 +241,9 @@ category = "categories"
207241
// Maybe consider reusing the Source fs
208242
mf := afero.NewMemMapFs()
209243
th, h := newTestSitesFromConfig(b, mf, siteConfig,
210-
"layouts/_default/single.html", `Single HTML|{{ .Title }}|{{ .Content }}`,
244+
"layouts/_default/single.html", `Single HTML|{{ .Title }}|{{ .Content }}|{{ partial "myPartial" . }} `,
211245
"layouts/_default/list.html", `List HTML|{{ .Title }}|{{ .Content }}`,
246+
"layouts/partials/myPartial.html", `Partial: {{ "Hello **world**!" | markdownify }}`,
212247
"layouts/shortcodes/myShortcode.html", `<p>MyShortcode</p>`)
213248

214249
fs := th.Fs

0 commit comments

Comments
 (0)