mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
markup/goldmark: Improve benchmark
This commit is contained in:
parent
85e2ac1a44
commit
34d1150d92
1 changed files with 31 additions and 28 deletions
|
@ -327,7 +327,7 @@ D.
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkCodeblocks(b *testing.B) {
|
func BenchmarkCodeblocks(b *testing.B) {
|
||||||
files := `
|
filesTemplate := `
|
||||||
-- config.toml --
|
-- config.toml --
|
||||||
[markup]
|
[markup]
|
||||||
[markup.highlight]
|
[markup.highlight]
|
||||||
|
@ -356,45 +356,48 @@ func main() {
|
||||||
}
|
}
|
||||||
FENCE
|
FENCE
|
||||||
|
|
||||||
FENCEbash
|
FENCEunknownlexer
|
||||||
#!/bin/bash
|
hello
|
||||||
# Usage: Hello World Bash Shell Script Using Variables
|
|
||||||
# Author: Vivek Gite
|
|
||||||
# -------------------------------------------------
|
|
||||||
|
|
||||||
# Define bash shell variable called var
|
|
||||||
# Avoid spaces around the assignment operator (=)
|
|
||||||
var="Hello World"
|
|
||||||
|
|
||||||
# print it
|
|
||||||
echo "$var"
|
|
||||||
|
|
||||||
# Another way of printing it
|
|
||||||
printf "%s\n" "$var"
|
|
||||||
FENCE
|
FENCE
|
||||||
`
|
`
|
||||||
|
|
||||||
content = strings.ReplaceAll(content, "FENCE", "```")
|
content = strings.ReplaceAll(content, "FENCE", "```")
|
||||||
|
|
||||||
for i := 1; i < 100; i++ {
|
for i := 1; i < 100; i++ {
|
||||||
files += fmt.Sprintf("\n-- content/posts/p%d.md --\n"+content, i+1)
|
filesTemplate += fmt.Sprintf("\n-- content/posts/p%d.md --\n"+content, i+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := hugolib.IntegrationTestConfig{
|
runBenchmark := func(files string, b *testing.B) {
|
||||||
T: b,
|
cfg := hugolib.IntegrationTestConfig{
|
||||||
TxtarString: files,
|
T: b,
|
||||||
}
|
TxtarString: files,
|
||||||
builders := make([]*hugolib.IntegrationTestBuilder, b.N)
|
}
|
||||||
|
builders := make([]*hugolib.IntegrationTestBuilder, b.N)
|
||||||
|
|
||||||
for i := range builders {
|
for i := range builders {
|
||||||
builders[i] = hugolib.NewIntegrationTestBuilder(cfg)
|
builders[i] = hugolib.NewIntegrationTestBuilder(cfg)
|
||||||
|
}
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
builders[i].Build()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b.ResetTimer()
|
b.Run("Default", func(b *testing.B) {
|
||||||
|
runBenchmark(filesTemplate, b)
|
||||||
|
})
|
||||||
|
|
||||||
|
b.Run("Hook no higlight", func(b *testing.B) {
|
||||||
|
files := filesTemplate + `
|
||||||
|
-- layouts/_default/_markup/render-codeblock.html --
|
||||||
|
{{ .Inner }}
|
||||||
|
`
|
||||||
|
|
||||||
|
runBenchmark(files, b)
|
||||||
|
})
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
|
||||||
builders[i].Build()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iisse #8959
|
// Iisse #8959
|
||||||
|
|
Loading…
Reference in a new issue