forked from mirror/go-json
Fix benchmark source
This commit is contained in:
parent
016803b843
commit
9eaa46775c
|
@ -10,7 +10,7 @@ import (
|
|||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
func Benchmark_Decode_SmallStruct_EncodingJson(b *testing.B) {
|
||||
func Benchmark_Decode_SmallStruct_Unmarshal_EncodingJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for n := 0; n < b.N; n++ {
|
||||
result := SmallPayload{}
|
||||
|
@ -20,7 +20,7 @@ func Benchmark_Decode_SmallStruct_EncodingJson(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_JsonIter(b *testing.B) {
|
||||
func Benchmark_Decode_SmallStruct_Unmarshal_JsonIter(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for n := 0; n < b.N; n++ {
|
||||
result := SmallPayload{}
|
||||
|
@ -30,7 +30,71 @@ func Benchmark_Decode_SmallStruct_JsonIter(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_GoJayDecode(b *testing.B) {
|
||||
func Benchmark_Decode_SmallStruct_Unmarshal_GoJay(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for n := 0; n < b.N; n++ {
|
||||
result := SmallPayload{}
|
||||
if err := gojay.UnmarshalJSONObject(SmallFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_Unmarshal_GoJayUnsafe(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := SmallPayload{}
|
||||
if err := gojay.Unsafe.UnmarshalJSONObject(SmallFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_Unmarshal_GoJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := SmallPayload{}
|
||||
if err := gojson.Unmarshal(SmallFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_Unmarshal_GoJsonNoEscape(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := SmallPayload{}
|
||||
if err := gojson.UnmarshalNoEscape(SmallFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_Stream_EncodingJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(SmallFixture)
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := SmallPayload{}
|
||||
reader.Reset(SmallFixture)
|
||||
if err := json.NewDecoder(reader).Decode(&result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_Stream_JsonIter(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(SmallFixture)
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := SmallPayload{}
|
||||
reader.Reset(SmallFixture)
|
||||
if err := jsoniter.NewDecoder(reader).Decode(&result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_Stream_GoJay(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(SmallFixture)
|
||||
for n := 0; n < b.N; n++ {
|
||||
|
@ -42,27 +106,7 @@ func Benchmark_Decode_SmallStruct_GoJayDecode(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_GoJay(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for n := 0; n < b.N; n++ {
|
||||
result := SmallPayload{}
|
||||
if err := gojay.UnmarshalJSONObject(SmallFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_GoJayUnsafe(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := SmallPayload{}
|
||||
if err := gojay.Unsafe.UnmarshalJSONObject(SmallFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_GoJsonDecode(b *testing.B) {
|
||||
func Benchmark_Decode_SmallStruct_Stream_GoJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
reader := bytes.NewReader(SmallFixture)
|
||||
for i := 0; i < b.N; i++ {
|
||||
|
@ -74,26 +118,6 @@ func Benchmark_Decode_SmallStruct_GoJsonDecode(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_GoJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := SmallPayload{}
|
||||
if err := gojson.Unmarshal(SmallFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_SmallStruct_GoJsonNoEscape(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
result := SmallPayload{}
|
||||
if err := gojson.UnmarshalNoEscape(SmallFixture, &result); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Benchmark_Decode_MediumStruct_EncodingJson(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for n := 0; n < b.N; n++ {
|
||||
|
|
Loading…
Reference in New Issue