-
Notifications
You must be signed in to change notification settings - Fork 3
/
bench_test.go
90 lines (75 loc) · 1.58 KB
/
bench_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package dotenv_test
import (
"testing"
"github.com/profclems/go-dotenv"
)
func BenchmarkDotenv_Load(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
config := dotenv.New()
config.SetConfigFile("fixtures/large.env")
err := config.Load()
if err != nil {
b.Fatal(err)
}
}
}
func BenchmarkDotenv_instance(b *testing.B) {
config := dotenv.New()
config.SetConfigFile("fixtures/large.env")
err := config.Load()
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
b.Run("Get", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = config.Get("DB_USERNAME")
}
})
b.ResetTimer()
// benchmark Get for a key that does not exist
b.Run("Get_NotExist", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = config.Get("DB_USERNAME_NOT_EXIST")
}
})
b.ResetTimer()
b.Run("Set", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
config.Set("APP_NAME", "My App")
}
})
}
func BenchmarkDotenv_global(b *testing.B) {
dotenv.SetConfigFile("fixtures/large.env")
err := dotenv.Load()
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
b.Run("Get", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = dotenv.Get("DB_USERNAME")
}
})
b.ResetTimer()
// benchmark Get for a key that does not exist
b.Run("Get_NotExist", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = dotenv.Get("DB_USERNAME_NOT_EXIST")
}
})
b.ResetTimer()
b.Run("Set", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
dotenv.Set("DB_USERNAME", "My App")
}
})
}