Add a list terms benchmark
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 19 Feb 2020 08:01:02 +0000 (09:01 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 19 Feb 2020 08:08:32 +0000 (09:08 +0100)
See #6905

hugolib/site_benchmark_new_test.go

index 2e3842d3877db41cb8d928e4757679ac6e207015..4ffeaa8a17e08368ef12f1d38c3347f381420069 100644 (file)
@@ -375,6 +375,56 @@ contentDir="content/sv"
 
                        },
                },
+               {"List terms", func(b testing.TB) *sitesBuilder {
+
+                       pageTemplateTemplate := `
+{{ $taxo := "categories" }}
+<ul>
+    {{ range .Param $taxo }}
+        {{ $name := . }}
+        {{ with $.Site.GetPage (printf "/%s/%s" $taxo ($name | urlize)) }}
+            <li><a href="{{ .Permalink }}">{{ $name }}</a></li>
+        {{ end }}
+    {{ end }}
+</ul>
+`
+
+                       sb := newTestSitesBuilder(b).WithConfigFile("toml", `
+baseURL = "https://example.com"
+`)
+
+                       sb.WithTemplates("_default/single.html", pageTemplateTemplate)
+
+                       r := rand.New(rand.NewSource(99))
+
+                       createContent := func(dir, name string) {
+                               var content string
+                               if strings.Contains(name, "_index") {
+                                       content = pageContent(1)
+                               } else {
+                                       content = pageContentWithCategory(1, fmt.Sprintf("category%d", r.Intn(5)+1))
+                                       sb.WithContent(filepath.Join("content", dir, name), content)
+                               }
+                       }
+
+                       for level := 1; level <= r.Intn(5)+1; level++ {
+                               sectionDir := path.Join(strings.Repeat("section/", level))
+                               createContent(sectionDir, "_index.md")
+                               for i := 1; i <= r.Intn(33); i++ {
+                                       leafBundleDir := path.Join(sectionDir, fmt.Sprintf("bundle%d", i))
+                                       createContent(leafBundleDir, "index.md")
+                               }
+                       }
+
+                       return sb
+               },
+                       func(s *sitesBuilder) {
+                               s.AssertFileContent("public/section/bundle8/index.html", ` <li><a href="https://example.com/categories/category1/">category1</a></li>`)
+                               s.Assert(len(s.H.Sites), qt.Equals, 1)
+                               s.Assert(len(s.H.Sites[0].RegularPages()), qt.Equals, 35)
+
+                       },
+               },
        }
 
        return benchmarks