forked from lestrrat-go/xslate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
godriver.go
63 lines (53 loc) · 1.38 KB
/
godriver.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
package main
import (
"bufio"
"flag"
"fmt"
prof "github.com/davecheney/profile"
"github.com/lestrrat/go-xslate"
"io"
"io/ioutil"
"os"
"time"
)
var iter = flag.Int("iterations", 100, "Number of iterations to perform")
var cacheLevel = flag.Int("cache", 1, "Use of cache (0=no cache, 1=cache + verify freshness, 2=always use cache)")
var profile = flag.Bool("profile", false, "Generate profile")
var template = flag.String("template", "hello.tx", "Template file to use")
var stdout = flag.Bool("stdout", false, "Direct output to stdout")
func main() {
flag.Parse()
tx, _ := xslate.New(xslate.Args{
"Loader": xslate.Args{
"CacheLevel": *cacheLevel,
},
})
t0 := time.Now()
if *profile {
config := prof.Config{
CPUProfile: true,
MemProfile: true,
BlockProfile: true,
ProfilePath: ".",
}
defer prof.Start(&config).Stop()
}
var output io.Writer
if *stdout {
output = os.Stdout
} else {
output = ioutil.Discard
}
f := bufio.NewWriter(output)
for i := 0; i < *iter; i++ {
err := tx.RenderInto(f, *template, nil)
if err != nil {
io.WriteString(os.Stderr, err.Error())
}
f.Flush()
}
elapsed := time.Since(t0)
fmt.Printf("* Elapsed %f secs\n", float64(elapsed.Seconds()))
fmt.Printf("* Secs per iter: %f sec/iter\n", float64(elapsed.Seconds())/float64(*iter))
fmt.Printf("* Iter per sec: %f iter/sec\n", float64(*iter)/float64(elapsed.Seconds()))
}