aboutsummaryrefslogtreecommitdiff
path: root/src/text/template/parse/parse_test.go
diff options
context:
space:
mode:
authorAriel Mashraki <ariel@mashraki.co.il>2019-10-01 18:39:29 +0300
committerEmmanuel Odeke <emm.odeke@gmail.com>2019-10-01 19:03:51 +0000
commit86cd6c2ee5c5e4c5b5edf4ea8d1c85f80d9706a8 (patch)
treed85294a11881143fb36e2978263b9f5088cb5d95 /src/text/template/parse/parse_test.go
parent09c9bced825593aedfd79af5c35916392f43113c (diff)
downloadgo-86cd6c2ee5c5e4c5b5edf4ea8d1c85f80d9706a8.tar.xz
text/template/parse: use strings.Builder in Chain and List nodes
This CL is a continuation of 198078. Benchmark output: benchmark old ns/op new ns/op delta BenchmarkParseLarge-8 24759165 24516563 -0.98% BenchmarkVariableString-8 115 115 +0.00% BenchmarkListString-8 924 680 -26.41% benchmark old allocs new allocs delta BenchmarkVariableString-8 3 3 +0.00% BenchmarkListString-8 14 13 -7.14% benchmark old bytes new bytes delta BenchmarkVariableString-8 72 72 +0.00% BenchmarkListString-8 512 424 -17.19% Change-Id: I9ec48fe4832437c556a5fa94d4cbf6e29e28d944 Reviewed-on: https://go-review.googlesource.com/c/go/+/198080 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/text/template/parse/parse_test.go')
-rw-r--r--src/text/template/parse/parse_test.go22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/text/template/parse/parse_test.go b/src/text/template/parse/parse_test.go
index 371de5d67c..86a100bb5f 100644
--- a/src/text/template/parse/parse_test.go
+++ b/src/text/template/parse/parse_test.go
@@ -554,7 +554,7 @@ func BenchmarkParseLarge(b *testing.B) {
}
}
-var sink string
+var sinkv, sinkl string
func BenchmarkVariableString(b *testing.B) {
v := &VariableNode{
@@ -563,9 +563,25 @@ func BenchmarkVariableString(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
- sink = v.String()
+ sinkv = v.String()
}
- if sink == "" {
+ if sinkv == "" {
+ b.Fatal("Benchmark was not run")
+ }
+}
+
+func BenchmarkListString(b *testing.B) {
+ text := `{{ (printf .Field1.Field2.Field3).Value }}`
+ tree, err := New("bench").Parse(text, "", "", make(map[string]*Tree), builtins)
+ if err != nil {
+ b.Fatal(err)
+ }
+ b.ResetTimer()
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ sinkl = tree.Root.String()
+ }
+ if sinkl == "" {
b.Fatal("Benchmark was not run")
}
}