hugolib: Add BenchmarkGetPage
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 23 May 2017 09:10:15 +0000 (12:10 +0300)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 23 May 2017 09:10:15 +0000 (12:10 +0300)
hugolib/site_test.go
hugolib/testhelpers_test.go

index 3868055e95ef16770f850afda65fdd9d08de7d53..bf5f9d547640871cd839cc56662d569fb1536cad 100644 (file)
@@ -1105,3 +1105,33 @@ func TestSourceRelativeLinkFileing(t *testing.T) {
                }
        }
 }
+
+func BenchmarkGetPage(b *testing.B) {
+       var (
+               cfg, fs = newTestCfg()
+       )
+
+       for i := 0; i < 10; i++ {
+               for j := 0; j < 100; j++ {
+                       writeSource(b, fs, filepath.Join("content", fmt.Sprintf("sect%d", i), fmt.Sprintf("page%d.md", j)), "CONTENT")
+               }
+       }
+
+       s := buildSingleSite(b, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true})
+
+       b.ResetTimer()
+       for i := 0; i < b.N; i++ {
+               home := s.getPage(KindHome)
+               if home == nil {
+                       b.Fatal("Home is nil")
+               }
+
+               for i := 0; i < 10; i++ {
+                       sect := fmt.Sprintf("sect%d", i)
+                       p := s.getPage(KindSection, sect)
+                       if p == nil {
+                               b.Fatal(fmt.Sprintf("Section %q is nil", sect))
+                       }
+               }
+       }
+}
index f82399eef4bd0e2a98ac6de2fe085a45c4c8ae09..5b3012a1d58a9f257e60753a62e621da974222e7 100644 (file)
@@ -182,11 +182,11 @@ func createWithTemplateFromNameValues(additionalTemplates ...string) func(templ
        }
 }
 
-func buildSingleSite(t *testing.T, depsCfg deps.DepsCfg, buildCfg BuildCfg) *Site {
+func buildSingleSite(t testing.TB, depsCfg deps.DepsCfg, buildCfg BuildCfg) *Site {
        return buildSingleSiteExpected(t, false, depsCfg, buildCfg)
 }
 
-func buildSingleSiteExpected(t *testing.T, expectBuildError bool, depsCfg deps.DepsCfg, buildCfg BuildCfg) *Site {
+func buildSingleSiteExpected(t testing.TB, expectBuildError bool, depsCfg deps.DepsCfg, buildCfg BuildCfg) *Site {
        h, err := NewHugoSites(depsCfg)
 
        require.NoError(t, err)