forked from rbaliyan/config
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_test.go
More file actions
118 lines (94 loc) · 2.12 KB
/
benchmark_test.go
File metadata and controls
118 lines (94 loc) · 2.12 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package config_test
import (
"context"
"testing"
"github.com/rbaliyan/config"
"github.com/rbaliyan/config/memory"
)
func BenchmarkManagerGet(b *testing.B) {
ctx := context.Background()
store := memory.NewStore()
_ = store.Connect(ctx)
defer store.Close(ctx)
_, _ = store.Set(ctx, "bench", "key", config.NewValue("hello"))
mgr, _ := config.New(config.WithStore(store))
_ = mgr.Connect(ctx)
defer mgr.Close(ctx)
cfg := mgr.Namespace("bench")
b.ResetTimer()
for b.Loop() {
_, _ = cfg.Get(ctx, "key")
}
}
func BenchmarkManagerGetCached(b *testing.B) {
ctx := context.Background()
store := memory.NewStore()
_ = store.Connect(ctx)
defer store.Close(ctx)
_, _ = store.Set(ctx, "bench", "key", config.NewValue(42))
mgr, _ := config.New(config.WithStore(store))
_ = mgr.Connect(ctx)
defer mgr.Close(ctx)
cfg := mgr.Namespace("bench")
// Prime cache
_, _ = cfg.Get(ctx, "key")
b.ResetTimer()
for b.Loop() {
_, _ = cfg.Get(ctx, "key")
}
}
func BenchmarkNewValue(b *testing.B) {
for b.Loop() {
config.NewValue(42)
}
}
func BenchmarkValueInt64(b *testing.B) {
v := config.NewValue(42)
b.ResetTimer()
for b.Loop() {
_, _ = v.Int64()
}
}
func BenchmarkValueString(b *testing.B) {
v := config.NewValue("hello world")
b.ResetTimer()
for b.Loop() {
_, _ = v.String()
}
}
func BenchmarkValueMarshal(b *testing.B) {
v := config.NewValue(map[string]any{"host": "localhost", "port": 5432})
b.ResetTimer()
for b.Loop() {
_, _ = v.Marshal()
}
}
func BenchmarkMarkStale(b *testing.B) {
v := config.NewValue("hello")
b.ResetTimer()
for b.Loop() {
config.MarkStale(v)
}
}
func BenchmarkStoreGet(b *testing.B) {
ctx := context.Background()
store := memory.NewStore()
_ = store.Connect(ctx)
defer store.Close(ctx)
_, _ = store.Set(ctx, "bench", "key", config.NewValue("value"))
b.ResetTimer()
for b.Loop() {
_, _ = store.Get(ctx, "bench", "key")
}
}
func BenchmarkStoreSet(b *testing.B) {
ctx := context.Background()
store := memory.NewStore()
_ = store.Connect(ctx)
defer store.Close(ctx)
v := config.NewValue("value")
b.ResetTimer()
for b.Loop() {
_, _ = store.Set(ctx, "bench", "key", v)
}
}