diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-23 12:10:15 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-05-23 12:10:15 +0300 |
commit | 6c560288a6329305ae3327a589e072e56bc9970d (patch) | |
tree | 693cad3ad2c5ede8306d1b51e1d44b33a8577dc7 /hugolib | |
parent | 89b85aede15cbf6f03e59ede92cd3e99a544632e (diff) |
hugolib: Add BenchmarkGetPage
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/site_test.go | 30 | ||||
-rw-r--r-- | hugolib/testhelpers_test.go | 4 |
2 files changed, 32 insertions, 2 deletions
diff --git a/hugolib/site_test.go b/hugolib/site_test.go index 3868055e9..bf5f9d547 100644 --- a/hugolib/site_test.go +++ b/hugolib/site_test.go @@ -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)) + } + } + } +} diff --git a/hugolib/testhelpers_test.go b/hugolib/testhelpers_test.go index f82399eef..5b3012a1d 100644 --- a/hugolib/testhelpers_test.go +++ b/hugolib/testhelpers_test.go @@ -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) |