diff --git a/README.md b/README.md index ad4451c66..b8dae92d4 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,14 @@ go tool covdata percent -i=./coverage/generate,./coverage/unit go tool covdata textfmt -i=./coverage/generate,./coverage/unit -o coverage.out ``` +### benchmark + +Run benchmarks. + +```sh +go run ./cmd/templ generate && go test ./... -bench=. -benchmem +``` + ### lint ```sh diff --git a/benchmarks/templ/render_test.go b/benchmarks/templ/render_test.go index ac8a11d72..6f1e25786 100644 --- a/benchmarks/templ/render_test.go +++ b/benchmarks/templ/render_test.go @@ -6,9 +6,11 @@ import ( "io" "strings" "testing" + + "github.com/a-h/templ/parser/v2" ) -func BenchmarkTempl(b *testing.B) { +func BenchmarkTemplRender(b *testing.B) { b.ReportAllocs() t := Render(Person{ Name: "Luiz Bonfa", @@ -25,6 +27,21 @@ func BenchmarkTempl(b *testing.B) { } } +// go:embed template.templ +var parserBenchmarkTemplate string + +func BenchmarkTemplParser(b *testing.B) { + for i := 0; i < b.N; i++ { + tf, err := parser.ParseString(parserBenchmarkTemplate) + if err != nil { + b.Fatal(err) + } + if tf.Package.Expression.Value == "" { + b.Fatal("unexpected nil template") + } + } +} + var goTemplate = template.Must(template.New("example").Parse(`