Benchmark large document and run in CI (#246) Fixes #229
Markus Wüstenberg markus@maragu.dk
Wed, 05 Mar 2025 12:00:11 +0100
3 files changed, 42 insertions(+), 2 deletions(-)
M .github/workflows/ci.yml → .github/workflows/ci.yml
@@ -49,6 +49,27 @@ uses: codecov/codecov-action@v5 with: token: ${{ secrets.CODECOV_TOKEN }} + benchmark: + name: Benchmark + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + check-latest: true + + - name: Run Benchmarks + run: | + echo "# Benchmark Results" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + go test -bench=. ./... 2>&1 | tee -a $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + lint: name: Lint runs-on: ubuntu-latest
M html/elements_test.go → html/elements_test.go
@@ -3,6 +3,7 @@ import ( "errors" "fmt" + "strings" "testing" g "maragu.dev/gomponents" @@ -164,3 +165,22 @@ assert.Equal(t, fmt.Sprintf(`<%v id="hat">`, test.Name), n) }) } } + +func BenchmarkLargeHTMLDocument(b *testing.B) { + b.ReportAllocs() + + for i := 0; i < b.N; i++ { + elements := make([]g.Node, 0, 10000) + + for i := 0; i < 5000; i++ { + elements = append(elements, + Div(Class("foo")), + Span(Class("bar")), + ) + } + doc := Div(elements...) + + var sb strings.Builder + _ = doc.Render(&sb) + } +}