Repository navigation
Expand file tree
/
Copy pathbench_test.go
More file actions
89 lines (81 loc) · 1.55 KB
/
Copy pathbench_test.go
File metadata and controls
89 lines (81 loc) · 1.55 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package tinyconf
import (
"context"
"testing"
"time"
)
type benchHTTP struct {
Host string
Port int
Timeout time.Duration
}
type benchConfig struct {
Name string
Level string
Hosts []string
Labels map[string]string
Database struct {
Host string
Port int
User string
Password string `hidden:"true"`
}
HTTP benchHTTP
}
func newBenchManager(b *testing.B) *Manager {
b.Helper()
c, err := New(WithDriver(&staticMockDriver{}))
if err != nil {
b.Fatal(err)
}
conf := &benchConfig{}
if err = c.Register(conf); err != nil {
b.Fatal(err)
}
if err = c.Parse(context.Background(), conf); err != nil {
b.Fatal(err)
}
return c
}
func BenchmarkParse(b *testing.B) {
c := newBenchManager(b)
conf := &benchConfig{}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := c.Parse(context.Background(), conf); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkParse_SubConfig(b *testing.B) {
c := newBenchManager(b)
http := &benchHTTP{}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := c.Parse(context.Background(), http); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkCurrent(b *testing.B) {
c := newBenchManager(b)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if Current[benchConfig](c) == nil {
b.Fatal("no current version")
}
}
}
func BenchmarkCurrent_SubConfig(b *testing.B) {
c := newBenchManager(b)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if Current[benchHTTP](c) == nil {
b.Fatal("no current version")
}
}
}