Skip to content

Commit

Permalink
Add benchmark target for bigdata test
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Jan 15, 2021
1 parent 39d5cd0 commit 0d97f97
Showing 1 changed file with 59 additions and 4 deletions.
63 changes: 59 additions & 4 deletions benchmarks/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (

"github.com/goccy/go-json"
jsoniter "github.com/json-iterator/go"
segmentiojson "github.com/segmentio/encoding/json"
"github.com/wI2L/jettison"
)

type codeResponse struct {
Expand Down Expand Up @@ -94,6 +96,24 @@ func codeInit() {
}
}

func Benchmark_EncodeBigData_GoJson(b *testing.B) {
b.ReportAllocs()
if codeJSON == nil {
b.StopTimer()
codeInit()
b.StartTimer()
}
b.RunParallel(func(pb *testing.PB) {
enc := json.NewEncoder(ioutil.Discard)
for pb.Next() {
if err := enc.Encode(&codeStruct); err != nil {
b.Fatal("Encode:", err)
}
}
})
b.SetBytes(int64(len(codeJSON)))
}

func Benchmark_EncodeBigData_EncodingJson(b *testing.B) {
b.ReportAllocs()
if codeJSON == nil {
Expand Down Expand Up @@ -131,15 +151,15 @@ func Benchmark_EncodeBigData_JsonIter(b *testing.B) {
b.SetBytes(int64(len(codeJSON)))
}

func Benchmark_EncodeBigData_GoJson(b *testing.B) {
func Benchmark_EncodeBigData_SegmentioJson(b *testing.B) {
b.ReportAllocs()
if codeJSON == nil {
b.StopTimer()
codeInit()
b.StartTimer()
}
b.RunParallel(func(pb *testing.PB) {
enc := json.NewEncoder(ioutil.Discard)
enc := segmentiojson.NewEncoder(ioutil.Discard)
for pb.Next() {
if err := enc.Encode(&codeStruct); err != nil {
b.Fatal("Encode:", err)
Expand All @@ -149,6 +169,24 @@ func Benchmark_EncodeBigData_GoJson(b *testing.B) {
b.SetBytes(int64(len(codeJSON)))
}

func Benchmark_MarshalBigData_GoJson(b *testing.B) {
b.ReportAllocs()
if codeJSON == nil {
b.StopTimer()
codeInit()
b.StartTimer()
}

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
if _, err := json.Marshal(&codeStruct); err != nil {
b.Fatal("Marshal:", err)
}
}
})
b.SetBytes(int64(len(codeJSON)))
}

func Benchmark_MarshalBigData_EncodingJson(b *testing.B) {
b.ReportAllocs()
if codeJSON == nil {
Expand Down Expand Up @@ -184,7 +222,7 @@ func Benchmark_MarshalBigData_JsonIter(b *testing.B) {
b.SetBytes(int64(len(codeJSON)))
}

func Benchmark_MarshalBigData_GoJson(b *testing.B) {
func Benchmark_MarshalBigData_Jettison(b *testing.B) {
b.ReportAllocs()
if codeJSON == nil {
b.StopTimer()
Expand All @@ -193,7 +231,24 @@ func Benchmark_MarshalBigData_GoJson(b *testing.B) {
}
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
if _, err := json.Marshal(&codeStruct); err != nil {
if _, err := jettison.Marshal(&codeStruct); err != nil {
b.Fatal("Marshal:", err)
}
}
})
b.SetBytes(int64(len(codeJSON)))
}

func Benchmark_MarshalBigData_SegmentioJson(b *testing.B) {
b.ReportAllocs()
if codeJSON == nil {
b.StopTimer()
codeInit()
b.StartTimer()
}
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
if _, err := segmentiojson.Marshal(&codeStruct); err != nil {
b.Fatal("Marshal:", err)
}
}
Expand Down

0 comments on commit 0d97f97

Please sign in to comment.