-
Notifications
You must be signed in to change notification settings - Fork 9
/
benchmark_test.go
64 lines (51 loc) · 1.16 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
// Copyright (c) 2024 The konf authors
// Use of this source code is governed by a MIT license found in the LICENSE file.
package konf_test
import (
"os"
"testing"
"github.com/nil-go/konf"
"github.com/nil-go/konf/internal/assert"
)
func BenchmarkLoad(b *testing.B) {
var config konf.Config
err := config.Load(mapLoader{"k": "v"})
assert.NoError(b, err)
var value string
assert.NoError(b, config.Unmarshal("k", &value))
assert.Equal(b, "v", value)
b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
var cfg konf.Config
_ = cfg.Load(mapLoader{"k": "v"})
}
})
}
func BenchmarkGet(b *testing.B) {
assert.Equal(b, os.Getenv("USER"), konf.Get[Value]("").User)
b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_ = konf.Get[Value]("")
}
})
}
func BenchmarkUnmarshal(b *testing.B) {
var value Value
err := konf.Unmarshal("", &value)
assert.NoError(b, err)
assert.Equal(b, os.Getenv("USER"), value.User)
b.ReportAllocs()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_ = konf.Unmarshal("", &value)
}
})
}
type Value struct {
User string
}