From 1208857c5ffddc91cf5124e7ccea88b71fc81403 Mon Sep 17 00:00:00 2001 From: maddalax Date: Fri, 27 Sep 2024 10:20:50 -0500 Subject: [PATCH] static / dynamic test --- framework/h/render_test.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/framework/h/render_test.go b/framework/h/render_test.go index dc84151..77325ae 100644 --- a/framework/h/render_test.go +++ b/framework/h/render_test.go @@ -2,6 +2,7 @@ package h import ( "bytes" + "github.com/google/uuid" "github.com/stretchr/testify/assert" "golang.org/x/net/html" "sort" @@ -104,13 +105,25 @@ func TestConditional(t *testing.T) { assert.Equal(t, "
", result) } -func BenchmarkMailTo(b *testing.B) { +func BenchmarkMailToStatic(b *testing.B) { + b.ReportAllocs() + ctx := RenderContext{ + builder: &strings.Builder{}, + } + page := MailTo("myemail") + for i := 0; i < b.N; i++ { + page.Render(&ctx) + ctx.builder.Reset() + } +} + +func BenchmarkMailToDynamic(b *testing.B) { b.ReportAllocs() ctx := RenderContext{ builder: &strings.Builder{}, } for i := 0; i < b.N; i++ { - MailTo().Render(&ctx) + MailTo(uuid.NewString()).Render(&ctx) ctx.builder.Reset() } } @@ -252,7 +265,7 @@ func ComplexPage() *Element { ) } -func MailTo() *Element { +func MailTo(email string) *Element { return Div( H1( Text("Contact Us"), @@ -264,7 +277,7 @@ func MailTo() *Element { Div( Text("email:"), A( - Href("mailto:"+"test@htmgo.dev"), + Href(email), Text("Email me"), ), ),