-
Notifications
You must be signed in to change notification settings - Fork 21
/
benchmark_test.go
88 lines (78 loc) · 1.51 KB
/
benchmark_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// +build bench
package gonja_test
import (
"io/ioutil"
"testing"
"github.com/noirbizarre/gonja"
tu "github.com/noirbizarre/gonja/testutils"
)
func BenchmarkFromCache(b *testing.B) {
for i := 0; i < b.N; i++ {
tpl, err := gonja.FromCache("testData/complex.tpl")
if err != nil {
b.Fatal(err)
}
_, err = tpl.Execute(tu.Fixtures)
if err != nil {
b.Fatal(err)
}
}
}
func BenchmarkFromFile(b *testing.B) {
for i := 0; i < b.N; i++ {
tpl, err := gonja.FromFile("testData/complex.tpl")
if err != nil {
b.Fatal(err)
}
_, err = tpl.Execute(tu.Fixtures)
if err != nil {
b.Fatal(err)
}
}
}
func BenchmarkExecute(b *testing.B) {
tpl, err := gonja.FromFile("testData/complex.tpl")
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = tpl.Execute(tu.Fixtures)
if err != nil {
b.Fatal(err)
}
}
}
func BenchmarkCompileAndExecute(b *testing.B) {
buf, err := ioutil.ReadFile("testData/complex.tpl")
if err != nil {
b.Fatal(err)
}
preloadedTpl := string(buf)
b.ResetTimer()
for i := 0; i < b.N; i++ {
tpl, err := gonja.FromString(preloadedTpl)
if err != nil {
b.Fatal(err)
}
_, err = tpl.Execute(tu.Fixtures)
if err != nil {
b.Fatal(err)
}
}
}
func BenchmarkParallelExecute(b *testing.B) {
tpl, err := gonja.FromFile("testData/complex.tpl")
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, err := tpl.Execute(tu.Fixtures)
if err != nil {
b.Fatal(err)
}
}
})
}