This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathperformance_test.go
73 lines (67 loc) · 1.75 KB
/
performance_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
package octetcounting
import (
"bytes"
"fmt"
"testing"
"github.com/influxdata/go-syslog/v3"
syslogtesting "github.com/influxdata/go-syslog/v3/testing"
)
// This is here to avoid compiler optimizations that
// could remove the actual call we are benchmarking
// during benchmarks
var benchParseResult syslog.Message
type benchCase struct {
input []byte
label string
maxLength int
}
var benchCases = []benchCase{
{
label: "Small Message Size",
input: []byte("48 <1>1 2003-10-11T22:14:15.003Z host.local - - - -25 <3>1 - host.local - - - -38 <2>1 - host.local su - - - κόσμε"),
},
{
label: "Default Max Message Size",
input: []byte(fmt.Sprintf(
"8192 <%d>%d %s %s %s %s %s - %s",
syslogtesting.MaxPriority,
syslogtesting.MaxVersion,
syslogtesting.MaxRFC3339MicroTimestamp,
string(syslogtesting.MaxHostname),
string(syslogtesting.MaxAppname),
string(syslogtesting.MaxProcID),
string(syslogtesting.MaxMsgID),
string(syslogtesting.MaxMessage),
)),
},
{
label: "UDP Max Message Size",
input: []byte(fmt.Sprintf(
"65529 <%d>%d %s %s %s %s %s - %s",
syslogtesting.MaxPriority,
syslogtesting.MaxVersion,
syslogtesting.MaxRFC3339MicroTimestamp,
string(syslogtesting.MaxHostname),
string(syslogtesting.MaxAppname),
string(syslogtesting.MaxProcID),
string(syslogtesting.MaxMsgID),
string(syslogtesting.LongerMaxMessage),
)),
maxLength: 65529,
},
}
func BenchmarkParse(b *testing.B) {
for _, tc := range benchCases {
tc := tc
if tc.maxLength == 0 {
tc.maxLength = 8192
}
m := NewParser(syslog.WithBestEffort())
b.Run(syslogtesting.RightPad(tc.label, 50), func(b *testing.B) {
for i := 0; i < b.N; i++ {
reader := bytes.NewReader(tc.input)
m.Parse(reader)
}
})
}
}