forked from brettlangdon/forge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
75 lines (66 loc) · 1.36 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
package forge_test
import (
"bytes"
"testing"
"github.com/go-aah/forge"
)
var exampleConfigBytes = []byte(`
# Global stuff
global = "global value";
# Primary stuff
primary {
string = "primary string value";
integer = 500;
float = 80.80;
negative = -50;
boolean = true;
not_true = FALSE;
nothing = NULL;
# Primary-sub stuff
sub {
key = "primary sub key value";
}
}
secondary {
another = "secondary another value";
global_reference = global;
primary_sub_key = primary.sub.key;
another_again = .another; # References secondary.another
_under = 50;
}
`)
var exampleConfigString = string(exampleConfigBytes)
var exampleConfigReader = bytes.NewReader(exampleConfigBytes)
func BenchmarkParseBytes(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := forge.ParseBytes(exampleConfigBytes)
if err != nil {
b.Fatal(err)
}
}
}
func BenchmarkParseString(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := forge.ParseString(exampleConfigString)
if err != nil {
b.Fatal(err)
}
}
}
func BenchmarkParseReader(b *testing.B) {
for i := 0; i < b.N; i++ {
exampleConfigReader.Seek(0, 0)
_, err := forge.ParseReader(exampleConfigReader)
if err != nil {
b.Fatal(err)
}
}
}
func BenchmarkParseFile(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := forge.ParseFile("./test.cfg")
if err != nil {
b.Fatal(err)
}
}
}