-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathbench_test.go
59 lines (51 loc) · 1.01 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
package logfmt
import (
"testing"
"time"
)
func BenchmarkScanner(b *testing.B) {
b.StopTimer()
data := []byte("measure.test=1 measure.foo=bar measure.time=2h measure=\"foo\"")
h := new(nopHandler)
b.SetBytes(int64(len(data)))
b.StartTimer()
for i := 0; i < b.N; i++ {
if err := gotoScanner(data, h); err != nil {
panic(err)
}
}
}
type nopHandler struct {
called bool
}
func (h *nopHandler) HandleLogfmt(key, val []byte) error {
h.called = true
return nil
}
func BenchmarkDecodeCustom(b *testing.B) {
data := []byte(`a=foo b=10ms c=cat E="123" d foo= emp=`)
h := new(nopHandler)
for i := 0; i < b.N; i++ {
if err := Unmarshal(data, h); err != nil {
panic(err)
}
}
if !h.called {
panic("handler not called")
}
}
func BenchmarkDecodeDefault(b *testing.B) {
data := []byte(`a=foo b=10ms c=cat E="123" d foo= emp=`)
var g struct {
A string
B time.Duration
C *string
E string
D bool
}
for i := 0; i < b.N; i++ {
if err := Unmarshal(data, &g); err != nil {
panic(err)
}
}
}