about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--gomponents.go4
-rw-r--r--gomponents_test.go16
3 files changed, 22 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index dc8bb1f..c453239 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,7 @@
-.PHONY: cover lint test
+.PHONY: benchmark cover lint test
+
+benchmark:
+	go test -bench=.
 
 cover:
 	go tool cover -html=cover.out
diff --git a/gomponents.go b/gomponents.go
index e6b89e1..f4b8467 100644
--- a/gomponents.go
+++ b/gomponents.go
@@ -129,9 +129,9 @@ type attr struct {
 
 func (a *attr) Render() string {
 	if a.value == nil {
-		return fmt.Sprintf(" %v", a.name)
+		return " " + a.name
 	}
-	return fmt.Sprintf(` %v="%v"`, a.name, *a.value)
+	return " " + a.name + `="` + *a.value + `"`
 }
 
 func (a *attr) Place() Placement {
diff --git a/gomponents_test.go b/gomponents_test.go
index 33d32d1..2efdd7a 100644
--- a/gomponents_test.go
+++ b/gomponents_test.go
@@ -52,6 +52,22 @@ func TestAttr(t *testing.T) {
 	})
 }
 
+func BenchmarkAttr(b *testing.B) {
+	b.Run("boolean attributes", func(b *testing.B) {
+		for i := 0; i < b.N; i++ {
+			a := g.Attr("hat")
+			a.Render()
+		}
+	})
+
+	b.Run("name-value attributes", func(b *testing.B) {
+		for i := 0; i < b.N; i++ {
+			a := g.Attr("hat", "party")
+			a.Render()
+		}
+	})
+}
+
 type outsider struct{}
 
 func (o outsider) Render() string {