]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
markup/goldmark: Improve benchmark
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 24 Nov 2022 10:51:01 +0000 (11:51 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 24 Nov 2022 11:04:44 +0000 (12:04 +0100)
markup/goldmark/integration_test.go

index e1d1445ee15a4eee2004ce7b86afeeddeaae0ca7..84617b2c8c89b6dc2fcec7481fc72e4d4dadf366 100644 (file)
@@ -327,7 +327,7 @@ D.
 }
 
 func BenchmarkCodeblocks(b *testing.B) {
-       files := `
+       filesTemplate := `
 -- config.toml --
 [markup]
   [markup.highlight]
@@ -356,45 +356,48 @@ func main() {
 }
 FENCE
 
-FENCEbash
-#!/bin/bash
-# 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"
+FENCEunknownlexer
+hello
 FENCE
 `
 
        content = strings.ReplaceAll(content, "FENCE", "```")
 
        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{
-               T:           b,
-               TxtarString: files,
-       }
-       builders := make([]*hugolib.IntegrationTestBuilder, b.N)
+       runBenchmark := func(files string, b *testing.B) {
+               cfg := hugolib.IntegrationTestConfig{
+                       T:           b,
+                       TxtarString: files,
+               }
+               builders := make([]*hugolib.IntegrationTestBuilder, b.N)
 
-       for i := range builders {
-               builders[i] = hugolib.NewIntegrationTestBuilder(cfg)
-       }
+               for i := range builders {
+                       builders[i] = hugolib.NewIntegrationTestBuilder(cfg)
+               }
 
-       b.ResetTimer()
+               b.ResetTimer()
 
-       for i := 0; i < b.N; i++ {
-               builders[i].Build()
+               for i := 0; i < b.N; i++ {
+                       builders[i].Build()
+               }
        }
+
+       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)
+       })
+
 }
 
 // Iisse #8959