-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
58 lines (52 loc) · 1.12 KB
/
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
50
51
52
53
54
55
56
57
58
package humane_test
import (
"context"
"errors"
"io"
"log/slog"
"testing"
"time"
"github.com/telemachus/humane"
)
var (
errTester = errors.New("random error")
timeTester = time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
)
var slogAttrs = []slog.Attr{
slog.Any("error", errTester),
slog.Bool("bool", true),
slog.Duration("duration", 5*time.Second),
slog.Float64("float64", 3.14),
slog.Group("group", slog.Int("d", 4), slog.Duration("a", 5*time.Second)),
slog.Int("int", 3),
slog.Int64("int64", 4),
slog.String("string", "random string"),
slog.Time("time", timeTester),
slog.Uint64("uint64", 0),
}
func BenchmarkSlog(b *testing.B) {
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
logger.LogAttrs(
context.Background(),
slog.LevelInfo,
"message",
slogAttrs...,
)
}
}
func BenchmarkHumane(b *testing.B) {
logger := slog.New(humane.NewHandler(io.Discard, nil))
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
logger.LogAttrs(
context.Background(),
slog.LevelInfo,
"message",
slogAttrs...,
)
}
}