Skip to content

Commit c1a8307

Browse files
committed
Add a shortcode benchmark
1 parent 0f8dc47 commit c1a8307

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Diff for: hugolib/shortcode_test.go

+52
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,58 @@ func BenchmarkReplaceShortcodeTokens(b *testing.B) {
297297
}
298298
}
299299

300+
func BenchmarkShortcodesInSite(b *testing.B) {
301+
files := `
302+
-- config.toml --
303+
-- layouts/shortcodes/mark1.md --
304+
{{ .Inner }}
305+
-- layouts/shortcodes/mark2.md --
306+
1. Item Mark2 1
307+
1. Item Mark2 2
308+
1. Item Mark2 2-1
309+
1. Item Mark2 3
310+
-- layouts/_default/single.html --
311+
{{ .Content }}
312+
`
313+
314+
content := `
315+
---
316+
title: "Markdown Shortcode"
317+
---
318+
319+
## List
320+
321+
1. List 1
322+
{{§ mark1 §}}
323+
1. Item Mark1 1
324+
1. Item Mark1 2
325+
{{§ mark2 §}}
326+
{{§ /mark1 §}}
327+
328+
`
329+
330+
for i := 1; i < 100; i++ {
331+
files += fmt.Sprintf("\n-- content/posts/p%d.md --\n"+content, i+1)
332+
}
333+
files = strings.ReplaceAll(files, "§", "%")
334+
335+
cfg := IntegrationTestConfig{
336+
T: b,
337+
TxtarString: files,
338+
}
339+
builders := make([]*IntegrationTestBuilder, b.N)
340+
341+
for i := range builders {
342+
builders[i] = NewIntegrationTestBuilder(cfg)
343+
}
344+
345+
b.ResetTimer()
346+
347+
for i := 0; i < b.N; i++ {
348+
builders[i].Build()
349+
}
350+
}
351+
300352
func TestReplaceShortcodeTokens(t *testing.T) {
301353
t.Parallel()
302354
for i, this := range []struct {

0 commit comments

Comments
 (0)