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