From 4ada09415dfa4c25c4fe9473fecf9e51ec740900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 21 Feb 2022 20:53:52 +0100 Subject: [PATCH] markup/goldmark: Add BenchmarkCodeblocks --- markup/goldmark/integration_test.go | 82 ++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/markup/goldmark/integration_test.go b/markup/goldmark/integration_test.go index eda2ac423..4ace04f75 100644 --- a/markup/goldmark/integration_test.go +++ b/markup/goldmark/integration_test.go @@ -15,6 +15,7 @@ package goldmark_test import ( "fmt" + "strings" "testing" "github.com/gohugoio/hugo/hugolib" @@ -131,7 +132,7 @@ title: "p1" ) } -func BenchmarkSiteWithRenderHooks(b *testing.B) { +func BenchmarkRenderHooks(b *testing.B) { files := ` -- config.toml -- -- layouts/_default/_markup/render-heading.html -- @@ -159,9 +160,15 @@ B. C. -## Hello3 [Test](https://example.com) +## Hello4 [Test](https://example.com) D. + +[Test](https://example.com) + +## Hello5 + + ` for i := 1; i < 100; i++ { @@ -184,3 +191,74 @@ D. builders[i].Build() } } + +func BenchmarkCodeblocks(b *testing.B) { + files := ` +-- config.toml -- +[markup] + [markup.highlight] + anchorLineNos = false + codeFences = true + guessSyntax = false + hl_Lines = '' + lineAnchors = '' + lineNoStart = 1 + lineNos = false + lineNumbersInTable = true + noClasses = true + style = 'monokai' + tabWidth = 4 +-- layouts/_default/single.html -- +{{ .Content }} +` + + content := ` + +FENCEgo +package main +import "fmt" +func main() { + fmt.Println("hello world") +} +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" +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) + } + + cfg := hugolib.IntegrationTestConfig{ + T: b, + TxtarString: files, + } + builders := make([]*hugolib.IntegrationTestBuilder, b.N) + + for i := range builders { + builders[i] = hugolib.NewIntegrationTestBuilder(cfg) + } + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + builders[i].Build() + } +}