@@ -6,12 +6,14 @@ import (
6
6
"html/template"
7
7
"log"
8
8
"testing"
9
+ texttemplate "text/template"
9
10
10
11
"github.com/valyala/quicktemplate"
11
12
"github.com/valyala/quicktemplate/testdata/templates"
12
13
)
13
14
14
15
var tpl = template .Must (template .ParseFiles ("../testdata/templates/bench.tpl" ))
16
+ var textTpl = texttemplate .Must (texttemplate .ParseFiles ("../testdata/templates/bench.tpl" ))
15
17
16
18
func init () {
17
19
// make sure that both template engines generate the same result
@@ -80,6 +82,32 @@ func benchmarkHTMLTemplate(b *testing.B, rowsCount int) {
80
82
})
81
83
}
82
84
85
+ func BenchmarkTextTemplate1 (b * testing.B ) {
86
+ benchmarkTextTemplate (b , 1 )
87
+ }
88
+
89
+ func BenchmarkTextTemplate10 (b * testing.B ) {
90
+ benchmarkTextTemplate (b , 10 )
91
+ }
92
+
93
+ func BenchmarkTextTemplate100 (b * testing.B ) {
94
+ benchmarkTextTemplate (b , 100 )
95
+ }
96
+
97
+ func benchmarkTextTemplate (b * testing.B , rowsCount int ) {
98
+ rows := getBenchRows (rowsCount )
99
+ b .RunParallel (func (pb * testing.PB ) {
100
+ bb := quicktemplate .AcquireByteBuffer ()
101
+ for pb .Next () {
102
+ if err := textTpl .Execute (bb , rows ); err != nil {
103
+ b .Fatalf ("unexpected error: %s" , err )
104
+ }
105
+ bb .Reset ()
106
+ }
107
+ quicktemplate .ReleaseByteBuffer (bb )
108
+ })
109
+ }
110
+
83
111
func getBenchRows (n int ) []templates.BenchRow {
84
112
rows := make ([]templates.BenchRow , n )
85
113
for i := 0 ; i < n ; i ++ {
0 commit comments