-
Notifications
You must be signed in to change notification settings - Fork 2
/
zax_benchmark_test.go
49 lines (40 loc) · 1.03 KB
/
zax_benchmark_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
package zax
import (
"context"
"testing"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var someFields = []zap.Field{
zap.String("field1", "value1"),
zap.String("field2", "value2"),
zap.Int("field3", 2),
}
func LogWithZap(logger *zap.Logger) {
logger.With(someFields...).Info("logging something")
}
func LogWithZax(logger *zap.Logger) {
ctx := context.Background()
Set(ctx, someFields)
logger.With(Get(ctx)...).Info("logging something")
}
func BenchmarkLoggingWithOnlyZap(b *testing.B) {
// Create a no-op logger that discards log output
logger := zap.NewExample()
logger = logger.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
return zapcore.NewNopCore()
}))
for i := 1; i <= b.N; i++ {
LogWithZap(logger)
}
}
func BenchmarkLoggingWithZax(b *testing.B) {
// Create a no-op logger that discards log output
logger := zap.NewExample()
logger = logger.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
return zapcore.NewNopCore()
}))
for i := 1; i <= b.N; i++ {
LogWithZax(logger)
}
}