-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjtoh_bench_test.go
45 lines (36 loc) · 996 Bytes
/
jtoh_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
package jtoh_test
import (
"fmt"
"io"
"strings"
"testing"
"github.com/madlambda/jtoh"
"github.com/madlambda/spells/iotest"
)
func BenchmarkNonJSONStreams(b *testing.B) {
msgCounts := []int{1000, 10000, 100000, 1000000}
testmsg := "non-json-test-msg\n"
selector := ":field"
benchmarkStream(b, selector, testmsg, msgCounts)
}
func BenchmarkJSONStreams(b *testing.B) {
msgCounts := []int{1000, 10000, 100000, 1000000}
testmsg := "{ \"field\" : \"bench\" }\n"
selector := ":field"
benchmarkStream(b, selector, testmsg, msgCounts)
}
func benchmarkStream(b *testing.B, selector, msg string, msgCounts []int) {
for _, msgCount := range msgCounts {
b.Run(fmt.Sprintf("%d Messages", msgCount), func(b *testing.B) {
for i := 0; i < b.N; i++ {
j, err := jtoh.New(selector)
if err != nil {
b.Errorf("unexpected error [%v]", err)
return
}
repeater := iotest.NewRepeatReader(strings.NewReader(msg), msgCount)
j.Do(repeater, io.Discard)
}
})
}
}