about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/ci.yml21
-rw-r--r--Makefile3
-rw-r--r--html/elements_test.go20
3 files changed, 42 insertions, 2 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 795d567..d448f1b 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -49,6 +49,27 @@ jobs:
         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
diff --git a/Makefile b/Makefile
index 67a1e22..885401e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 .PHONY: benchmark
 benchmark:
-	go test -bench=.
+	go test -bench=. ./...
 
 .PHONY: cover
 cover:
@@ -13,4 +13,3 @@ lint:
 .PHONY: test
 test:
 	go test -coverprofile=cover.out -shuffle on ./...
-
diff --git a/html/elements_test.go b/html/elements_test.go
index 5fe6268..7670af5 100644
--- a/html/elements_test.go
+++ b/html/elements_test.go
@@ -3,6 +3,7 @@ package html_test
 import (
 	"errors"
 	"fmt"
+	"strings"
 	"testing"
 
 	g "maragu.dev/gomponents"
@@ -164,3 +165,22 @@ func TestSimpleVoidKindElements(t *testing.T) {
 		})
 	}
 }
+
+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)
+	}
+}