-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench_test.go
101 lines (85 loc) · 2.38 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
91
92
93
94
95
96
97
98
99
100
101
package logger_test
import (
"bytes"
"log/slog"
"regexp"
"testing"
"github.com/mdouchement/logger"
"github.com/sirupsen/logrus"
)
// go test -bench . -run NONE -benchtime 5s
var result []byte
func BenchmarkLogrusGELF(b *testing.B) {
w := new(bytes.Buffer)
ll := logrus.New()
ll.SetOutput(w)
ll.SetFormatter(&logger.LogrusGELFFormatter{Hostname: "hostname"})
base := logger.WrapLogrus(ll)
var l logger.Logger
for i := 0; i < b.N; i++ {
l = base.WithPrefix("[prefix]")
l = l.WithField("f1", 42).WithField("f2", "42").WithField("f3", 42).WithField("f4", "42")
l = l.WithPrefixf("[%s]", 4242)
l.Info("message")
}
b.ReportAllocs()
result = w.Bytes()
}
func BenchmarkSlogGELF(b *testing.B) {
w := new(bytes.Buffer)
ll := slog.New(logger.NewSlogGELFHandler(w, &logger.SlogGELFOption{Hostname: "hostname"}))
base := logger.WrapSlog(ll)
var l logger.Logger
for i := 0; i < b.N; i++ {
l = base.WithPrefix("[prefix]")
l = l.WithField("f1", 42).WithField("f2", "42").WithField("f3", 42).WithField("f4", "42")
l = l.WithPrefixf("[%s]", 4242)
l.Info("message")
}
b.ReportAllocs()
result = w.Bytes()
}
func BenchmarkLogrusText(b *testing.B) {
w := new(bytes.Buffer)
ll := logrus.New()
ll.SetOutput(w)
ll.SetFormatter(&logger.LogrusTextFormatter{
DisableColors: false,
ForceColors: true,
ForceFormatting: true,
PrefixRE: regexp.MustCompile(`^(\[.*?\])\s`),
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
})
base := logger.WrapLogrus(ll)
var l logger.Logger
for i := 0; i < b.N; i++ {
l = base.WithPrefix("[prefix]")
l = l.WithField("f1", 42).WithField("f2", "42").WithField("f3", 42).WithField("f4", "42")
l = l.WithPrefixf("[%s]", 4242)
l.Info("message")
}
b.ReportAllocs()
result = w.Bytes()
}
func BenchmarkSlogText(b *testing.B) {
w := new(bytes.Buffer)
ll := slog.New(logger.NewSlogTextHandler(w, &logger.SlogTextOption{
DisableColors: false,
ForceColors: true,
ForceFormatting: true,
PrefixRE: regexp.MustCompile(`^(\[.*?\])\s`),
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
}))
base := logger.WrapSlog(ll)
var l logger.Logger
for i := 0; i < b.N; i++ {
l = base.WithPrefix("[prefix]")
l = l.WithField("f1", 42).WithField("f2", "42").WithField("f3", 42).WithField("f4", "42")
l = l.WithPrefixf("[%s]", 4242)
l.Info("message")
}
b.ReportAllocs()
result = w.Bytes()
}