-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvalue_test.go
55 lines (47 loc) · 1.17 KB
/
value_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
package metrics
import (
"fmt"
"runtime"
"testing"
"github.com/uber-go/tally"
"go.uber.org/net/metrics/tallypush"
)
func BenchmarkValueVector(b *testing.B) {
b.Run("getOrCreate", func(b *testing.B) {
vect := newCounterVector(metadata{varTagNames: []string{"key"}})
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := vect.getOrCreate([]string{"key", fmt.Sprint("val", i)})
if err != nil {
b.Fatal(err)
}
}
})
b.Run("get", func(b *testing.B) {
vect := newCounterVector(metadata{varTagNames: []string{"key"}})
_, err := vect.getOrCreate([]string{"key", "val0"})
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
runtime.KeepAlive(vect.MustGet("key", "val0"))
}
})
const _loopLimit = 10_000
b.Run(fmt.Sprint("loop", _loopLimit), func(b *testing.B) {
name := ""
vect := newCounterVector(metadata{Name: &name, varTagNames: []string{"key"}})
for i := 0; i < _loopLimit; i++ {
_, err := vect.getOrCreate([]string{"key", fmt.Sprint("val", i)})
if err != nil {
b.Fatal(err)
}
}
pusher := tallypush.New(tally.NoopScope)
b.ResetTimer()
for i := 0; i < b.N; i++ {
vect.push(pusher)
}
})
}