-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmarks_test.go
50 lines (42 loc) · 1.01 KB
/
benchmarks_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
package kvlog_test
import (
"io"
"os"
"testing"
"time"
"github.com/halimath/kvlog"
)
func BenchmarkKVLog_syncHandler_JSONLFormatter(b *testing.B) {
out, err := os.OpenFile("/dev/null", os.O_WRONLY, 0)
if err != nil {
b.Fatal(err)
}
defer out.Close()
l := kvlog.New(kvlog.NewSyncHandler(out, kvlog.JSONLFormatter()))
b.ResetTimer()
for i := 0; i < b.N; i++ {
l.Logs("some message",
kvlog.WithKV("spam", "eggs"),
kvlog.WithKV("foo", 17),
kvlog.WithKV("enabled", true),
kvlog.WithDur(time.Second),
)
}
}
func BenchmarkKVLog_syncHandler_noopFormatter(b *testing.B) {
out, err := os.OpenFile("/dev/null", os.O_WRONLY, 0)
if err != nil {
b.Fatal(err)
}
defer out.Close()
l := kvlog.New(kvlog.NewSyncHandler(out, kvlog.FormatterFunc(func(io.Writer, *kvlog.Event) error { return nil })))
b.ResetTimer()
for i := 0; i < b.N; i++ {
l.Logs("some message",
kvlog.WithKV("foo", 17),
kvlog.WithKV("enabled", true),
// Dur(time.Second).
kvlog.WithKV(kvlog.KeyDuration, time.Second),
)
}
}