-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathstats_test.go
66 lines (51 loc) · 1.52 KB
/
stats_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
package fastdns
import (
"encoding/hex"
"net/netip"
"testing"
"time"
)
func BenchmarkUpdateStats(b *testing.B) {
payload, _ := hex.DecodeString("8e5281800001000200000000047632657803636f6d0000020001c00c000200010000545f0014036b696d026e730a636c6f7564666c617265c011c00c000200010000545f000704746f6464c02a")
resp := AcquireMessage()
defer ReleaseMessage(resp)
err := ParseMessage(resp, payload, true)
if err != nil {
b.Errorf("ParseMessage(%+v) error: %+v", payload, err)
}
stats := &CoreStats{
Prefix: "coredns_",
Family: "1",
Proto: "udp",
Server: "dns://:53",
Zone: ".",
}
addr := netip.AddrPortFrom(netip.AddrFrom4([4]byte{127, 0, 0, 1}), 12345)
b.ResetTimer()
for i := 0; i < b.N; i++ {
stats.UpdateStats(addr, resp, time.Millisecond)
}
}
func BenchmarkAppendOpenMetrics(b *testing.B) {
payload, _ := hex.DecodeString("8e5281800001000200000000047632657803636f6d0000020001c00c000200010000545f0014036b696d026e730a636c6f7564666c617265c011c00c000200010000545f000704746f6464c02a")
resp := AcquireMessage()
defer ReleaseMessage(resp)
err := ParseMessage(resp, payload, true)
if err != nil {
b.Errorf("ParseMessage(%+v) error: %+v", payload, err)
}
stats := &CoreStats{
Prefix: "coredns_",
Family: "1",
Proto: "udp",
Server: "dns://:53",
Zone: ".",
}
addr := netip.AddrPortFrom(netip.AddrFrom4([4]byte{127, 0, 0, 1}), 12345)
stats.UpdateStats(addr, resp, time.Millisecond)
buf := make([]byte, 0, 32*1024)
b.ResetTimer()
for i := 0; i < b.N; i++ {
stats.AppendOpenMetrics(buf[:0])
}
}