File: decoder_bench_small_test.go

package info (click to toggle)
golang-github-francoispqt-gojay 1.2.13-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,456 kB
  • sloc: makefile: 86
file content (69 lines) | stat: -rw-r--r-- 1,746 bytes parent folder | download
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
60
61
62
63
64
65
66
67
68
69
package benchmarks

import (
	"encoding/json"
	_ "fmt"
	"testing"

	"github.com/buger/jsonparser"
	"github.com/francoispqt/gojay"
	"github.com/francoispqt/gojay/benchmarks"
	jsoniter "github.com/json-iterator/go"
	"github.com/mailru/easyjson"
)

func BenchmarkJSONDecodeObjSmall(b *testing.B) {
	b.ReportAllocs()
	for n := 0; n < b.N; n++ {
		result := benchmarks.SmallPayload{}
		json.Unmarshal(benchmarks.SmallFixture, &result)
	}
}

func nothing(_ ...interface{}) {}
func BenchmarkJSONParserSmall(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		jsonparser.GetInt(benchmarks.SmallFixture, "tz")
		jsonparser.GetInt(benchmarks.SmallFixture, "v")
		jsonparser.GetInt(benchmarks.SmallFixture, "sid")
		jsonparser.GetInt(benchmarks.SmallFixture, "st")
		jsonparser.GetInt(benchmarks.SmallFixture, "gr")
		jsonparser.Get(benchmarks.SmallFixture, "uuid")
		jsonparser.Get(benchmarks.SmallFixture, "ua")

		nothing()
	}
}

func BenchmarkJsonIterDecodeObjSmall(b *testing.B) {
	b.ReportAllocs()
	for n := 0; n < b.N; n++ {
		result := benchmarks.SmallPayload{}
		jsoniter.Unmarshal(benchmarks.SmallFixture, &result)
	}
}

func BenchmarkEasyJsonDecodeObjSmall(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		result := benchmarks.SmallPayload{}
		easyjson.Unmarshal(benchmarks.SmallFixture, &result)
	}
}

func BenchmarkGoJayDecodeObjSmall(b *testing.B) {
	b.ReportAllocs()
	for n := 0; n < b.N; n++ {
		result := benchmarks.SmallPayload{}
		gojay.UnmarshalJSONObject(benchmarks.SmallFixture, &result)
	}
}

func BenchmarkGoJayUnsafeDecodeObjSmall(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		result := benchmarks.SmallPayload{}
		gojay.Unsafe.UnmarshalJSONObject(benchmarks.SmallFixture, &result)
	}
}