-
Notifications
You must be signed in to change notification settings - Fork 13
/
haml_bench_test.go
57 lines (47 loc) · 925 Bytes
/
haml_bench_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
package gohaml
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"testing"
)
const fn = "test/test.haml"
var template string
func loadTemplate() {
if template != "" {
return
}
var (
file *os.File
err error
)
if file, err = os.Open(fn); err != nil {
fmt.Printf("couldn't open testfile: %s (%s)\n", fn, err)
os.Exit(1)
}
defer file.Close()
reader := bufio.NewReader(file)
bytes := make([]byte, 0)
if bytes, err = ioutil.ReadAll(reader); err != nil {
fmt.Printf("couldn't read testfile: %s (%s)\n", fn, err)
}
template = string(bytes)
}
func BenchmarkRender(b *testing.B) {
var (
engine *Engine
err error
)
b.StopTimer()
loadTemplate()
if engine, err = NewEngine(template); err != nil {
fmt.Printf("couldn't init engine from testfile: %s (%s)\n", fn, err)
os.Exit(1)
}
scope := make(map[string]interface{})
b.StartTimer()
for i := 0; i != b.N; i++ {
engine.Render(scope)
}
}