-
Notifications
You must be signed in to change notification settings - Fork 9
/
koanf_test.go
55 lines (44 loc) · 1.03 KB
/
koanf_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
// Copyright (c) 2024 The konf authors
// Use of this source code is governed by a MIT license found in the LICENSE file.
package benchmark_test
import (
"os"
"strings"
"testing"
"github.com/knadh/koanf/providers/env"
"github.com/knadh/koanf/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func BenchmarkKoanf_Get(b *testing.B) {
assert.Equal(b, os.Getenv("USER"), k.Get("user"))
b.ResetTimer()
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_ = k.Get("user")
}
})
}
func BenchmarkKoanf_Unmarshal(b *testing.B) {
var value struct {
User string
}
err := k.Unmarshal("", &value)
require.NoError(b, err)
assert.Equal(b, os.Getenv("USER"), value.User)
b.ResetTimer()
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_ = k.Unmarshal("", &value)
}
})
}
var k *koanf.Koanf
func init() {
k = koanf.New(".")
_ = k.Load(env.Provider("", ".", func(s string) string {
return strings.ReplaceAll(strings.ToLower(s), "_", ".")
}), nil)
}