forked from kevinburke/go-bindata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
74 lines (68 loc) · 1.42 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
package bindata_test
import (
"go/format"
"io/ioutil"
"os"
"path/filepath"
"testing"
bindata "github.com/kevinburke/go-bindata"
)
func dirSize(path string) (int64, error) {
var size int64
err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
if !info.IsDir() {
size += info.Size()
}
return err
})
return size, err
}
func BenchmarkBindata(b *testing.B) {
size, err := dirSize("testdata/benchmark")
if err != nil {
b.Fatal(err)
}
b.SetBytes(size)
cfg := &bindata.Config{
Package: "assets",
Input: []bindata.InputConfig{
{Path: "testdata/benchmark", Recursive: true},
},
Output: "testdata/assets/bindata.go",
NoMemCopy: false,
NoCompress: true,
Debug: false,
NoMetadata: true,
Mode: 0x0, ModTime: 0,
Ignore: nil,
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := bindata.Translate(cfg); err != nil {
b.Fatal(err)
}
}
}
var formatSink []byte
func BenchmarkFormatSource(b *testing.B) {
// https://github.com/golang/go/issues/26528
// unformatted.out is any large go-bindata source file.
data, err := ioutil.ReadFile("testdata/unformatted.out")
if os.IsNotExist(err) {
b.Skip("source file does not exist")
return
}
if err != nil {
b.Fatal(err)
}
b.SetBytes(int64(len(data)))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
formatSink, err = format.Source(data)
if err != nil {
b.Fatal(err)
}
}
}