123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- // +build use_jsoniter
- package benchmark
- import (
- "testing"
- jsoniter "github.com/json-iterator/go"
- )
- func BenchmarkJI_Unmarshal_M(b *testing.B) {
- b.SetBytes(int64(len(largeStructText)))
- for i := 0; i < b.N; i++ {
- var s LargeStruct
- err := jsoniter.Unmarshal(largeStructText, &s)
- if err != nil {
- b.Error(err)
- }
- }
- }
- func BenchmarkJI_Unmarshal_S(b *testing.B) {
- for i := 0; i < b.N; i++ {
- var s Entities
- err := jsoniter.Unmarshal(smallStructText, &s)
- if err != nil {
- b.Error(err)
- }
- }
- b.SetBytes(int64(len(smallStructText)))
- }
- func BenchmarkJI_Marshal_M(b *testing.B) {
- var l int64
- for i := 0; i < b.N; i++ {
- data, err := jsoniter.Marshal(&largeStructData)
- if err != nil {
- b.Error(err)
- }
- l = int64(len(data))
- }
- b.SetBytes(l)
- }
- func BenchmarkJI_Marshal_L(b *testing.B) {
- var l int64
- for i := 0; i < b.N; i++ {
- data, err := jsoniter.Marshal(&xlStructData)
- if err != nil {
- b.Error(err)
- }
- l = int64(len(data))
- }
- b.SetBytes(l)
- }
- func BenchmarkJI_Marshal_M_Parallel(b *testing.B) {
- var l int64
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- data, err := jsoniter.Marshal(&largeStructData)
- if err != nil {
- b.Error(err)
- }
- l = int64(len(data))
- }
- })
- b.SetBytes(l)
- }
- func BenchmarkJI_Marshal_L_Parallel(b *testing.B) {
- var l int64
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- data, err := jsoniter.Marshal(&xlStructData)
- if err != nil {
- b.Error(err)
- }
- l = int64(len(data))
- }
- })
- b.SetBytes(l)
- }
- func BenchmarkJI_Marshal_S(b *testing.B) {
- var l int64
- for i := 0; i < b.N; i++ {
- data, err := jsoniter.Marshal(&smallStructData)
- if err != nil {
- b.Error(err)
- }
- l = int64(len(data))
- }
- b.SetBytes(l)
- }
- func BenchmarkJI_Marshal_S_Parallel(b *testing.B) {
- var l int64
- b.RunParallel(func(pb *testing.PB) {
- for pb.Next() {
- data, err := jsoniter.Marshal(&smallStructData)
- if err != nil {
- b.Error(err)
- }
- l = int64(len(data))
- }
- })
- b.SetBytes(l)
- }
- func BenchmarkJI_Marshal_M_ToWriter(b *testing.B) {
- enc := jsoniter.NewEncoder(&DummyWriter{})
- for i := 0; i < b.N; i++ {
- err := enc.Encode(&largeStructData)
- if err != nil {
- b.Error(err)
- }
- }
- }
|