~mna/zerojson

ref: 780b8ea647d6b91e344b6dd20401a7f05b7f6317 zerojson/zerojson_bench_test.go -rw-r--r-- 613 bytes View raw
780b8ea6Martin Angers scan strings, start escapes 1 year, 1 month ago
                                                                                
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
package zerojson

import (
	"fmt"
	"io"
	"testing"
)

func BenchmarkTrue(b *testing.B) {
	benchmarkInput(b, "true")
}

func BenchmarkFalse(b *testing.B) {
	benchmarkInput(b, "false")
}

func BenchmarkNull(b *testing.B) {
	benchmarkInput(b, "null")
}

func benchmarkInput(b *testing.B, input string) {
	p := parser{
		input: []byte(fmt.Sprintf(" %s ", input)),
		emit: func(offset int, typ byte, v []byte, err error) error {
			if err == io.EOF {
				return nil
			}
			return err
		},
	}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		p.stack = stack{}
		if err := p.parse(); err != nil {
			b.Fatal(err)
		}
	}
}