|
5 | 5 | "encoding/json"
|
6 | 6 | "testing"
|
7 | 7 |
|
| 8 | + "github.com/bytedance/sonic" |
8 | 9 | gojay "github.com/francoispqt/gojay"
|
9 | 10 | gojson "github.com/goccy/go-json"
|
10 | 11 | jsoniter "github.com/json-iterator/go"
|
@@ -33,41 +34,51 @@ func Benchmark_Decode_SmallStruct_Unmarshal_FastJson(b *testing.B) {
|
33 | 34 | }
|
34 | 35 | }
|
35 | 36 |
|
36 |
| -func Benchmark_Decode_SmallStruct_Unmarshal_JsonIter(b *testing.B) { |
| 37 | +func Benchmark_Decode_SmallStruct_Unmarshal_SegmentioJson(b *testing.B) { |
37 | 38 | b.ReportAllocs()
|
38 | 39 | for n := 0; n < b.N; n++ {
|
39 | 40 | result := SmallPayload{}
|
40 |
| - if err := jsoniter.Unmarshal(SmallFixture, &result); err != nil { |
| 41 | + if err := segmentiojson.Unmarshal(SmallFixture, &result); err != nil { |
41 | 42 | b.Fatal(err)
|
42 | 43 | }
|
43 | 44 | }
|
44 | 45 | }
|
45 | 46 |
|
46 |
| -func Benchmark_Decode_SmallStruct_Unmarshal_GoJay(b *testing.B) { |
| 47 | +func Benchmark_Decode_SmallStruct_Unmarshal_Sonic(b *testing.B) { |
47 | 48 | b.ReportAllocs()
|
48 | 49 | for n := 0; n < b.N; n++ {
|
49 | 50 | result := SmallPayload{}
|
50 |
| - if err := gojay.UnmarshalJSONObject(SmallFixture, &result); err != nil { |
| 51 | + if err := sonic.Unmarshal(SmallFixture, &result); err != nil { |
51 | 52 | b.Fatal(err)
|
52 | 53 | }
|
53 | 54 | }
|
54 | 55 | }
|
55 | 56 |
|
56 |
| -func Benchmark_Decode_SmallStruct_Unmarshal_GoJayUnsafe(b *testing.B) { |
| 57 | +func Benchmark_Decode_SmallStruct_Unmarshal_JsonIter(b *testing.B) { |
57 | 58 | b.ReportAllocs()
|
58 |
| - for i := 0; i < b.N; i++ { |
| 59 | + for n := 0; n < b.N; n++ { |
59 | 60 | result := SmallPayload{}
|
60 |
| - if err := gojay.Unsafe.UnmarshalJSONObject(SmallFixture, &result); err != nil { |
| 61 | + if err := jsoniter.Unmarshal(SmallFixture, &result); err != nil { |
61 | 62 | b.Fatal(err)
|
62 | 63 | }
|
63 | 64 | }
|
64 | 65 | }
|
65 | 66 |
|
66 |
| -func Benchmark_Decode_SmallStruct_Unmarshal_SegmentioJson(b *testing.B) { |
| 67 | +func Benchmark_Decode_SmallStruct_Unmarshal_GoJay(b *testing.B) { |
67 | 68 | b.ReportAllocs()
|
68 | 69 | for n := 0; n < b.N; n++ {
|
69 | 70 | result := SmallPayload{}
|
70 |
| - if err := segmentiojson.Unmarshal(SmallFixture, &result); err != nil { |
| 71 | + if err := gojay.UnmarshalJSONObject(SmallFixture, &result); err != nil { |
| 72 | + b.Fatal(err) |
| 73 | + } |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +func Benchmark_Decode_SmallStruct_Unmarshal_GoJayUnsafe(b *testing.B) { |
| 78 | + b.ReportAllocs() |
| 79 | + for i := 0; i < b.N; i++ { |
| 80 | + result := SmallPayload{} |
| 81 | + if err := gojay.Unsafe.UnmarshalJSONObject(SmallFixture, &result); err != nil { |
71 | 82 | b.Fatal(err)
|
72 | 83 | }
|
73 | 84 | }
|
@@ -105,37 +116,37 @@ func Benchmark_Decode_SmallStruct_Stream_EncodingJson(b *testing.B) {
|
105 | 116 | }
|
106 | 117 | }
|
107 | 118 |
|
108 |
| -func Benchmark_Decode_SmallStruct_Stream_JsonIter(b *testing.B) { |
| 119 | +func Benchmark_Decode_SmallStruct_Stream_SegmentioJson(b *testing.B) { |
109 | 120 | b.ReportAllocs()
|
110 | 121 | reader := bytes.NewReader(SmallFixture)
|
111 | 122 | for i := 0; i < b.N; i++ {
|
112 | 123 | result := SmallPayload{}
|
113 | 124 | reader.Reset(SmallFixture)
|
114 |
| - if err := jsoniter.NewDecoder(reader).Decode(&result); err != nil { |
| 125 | + if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil { |
115 | 126 | b.Fatal(err)
|
116 | 127 | }
|
117 | 128 | }
|
118 | 129 | }
|
119 | 130 |
|
120 |
| -func Benchmark_Decode_SmallStruct_Stream_GoJay(b *testing.B) { |
| 131 | +func Benchmark_Decode_SmallStruct_Stream_JsonIter(b *testing.B) { |
121 | 132 | b.ReportAllocs()
|
122 | 133 | reader := bytes.NewReader(SmallFixture)
|
123 |
| - for n := 0; n < b.N; n++ { |
124 |
| - reader.Reset(SmallFixture) |
| 134 | + for i := 0; i < b.N; i++ { |
125 | 135 | result := SmallPayload{}
|
126 |
| - if err := gojay.NewDecoder(reader).DecodeObject(&result); err != nil { |
| 136 | + reader.Reset(SmallFixture) |
| 137 | + if err := jsoniter.NewDecoder(reader).Decode(&result); err != nil { |
127 | 138 | b.Fatal(err)
|
128 | 139 | }
|
129 | 140 | }
|
130 | 141 | }
|
131 | 142 |
|
132 |
| -func Benchmark_Decode_SmallStruct_Stream_SegmentioJson(b *testing.B) { |
| 143 | +func Benchmark_Decode_SmallStruct_Stream_GoJay(b *testing.B) { |
133 | 144 | b.ReportAllocs()
|
134 | 145 | reader := bytes.NewReader(SmallFixture)
|
135 |
| - for i := 0; i < b.N; i++ { |
136 |
| - result := SmallPayload{} |
| 146 | + for n := 0; n < b.N; n++ { |
137 | 147 | reader.Reset(SmallFixture)
|
138 |
| - if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil { |
| 148 | + result := SmallPayload{} |
| 149 | + if err := gojay.NewDecoder(reader).DecodeObject(&result); err != nil { |
139 | 150 | b.Fatal(err)
|
140 | 151 | }
|
141 | 152 | }
|
@@ -174,41 +185,51 @@ func Benchmark_Decode_MediumStruct_Unmarshal_FastJson(b *testing.B) {
|
174 | 185 | }
|
175 | 186 | }
|
176 | 187 |
|
177 |
| -func Benchmark_Decode_MediumStruct_Unmarshal_JsonIter(b *testing.B) { |
| 188 | +func Benchmark_Decode_MediumStruct_Unmarshal_Sonic(b *testing.B) { |
178 | 189 | b.ReportAllocs()
|
179 |
| - for n := 0; n < b.N; n++ { |
| 190 | + for i := 0; i < b.N; i++ { |
180 | 191 | result := MediumPayload{}
|
181 |
| - if err := jsoniter.Unmarshal(MediumFixture, &result); err != nil { |
| 192 | + if err := sonic.Unmarshal(MediumFixture, &result); err != nil { |
182 | 193 | b.Fatal(err)
|
183 | 194 | }
|
184 | 195 | }
|
185 | 196 | }
|
186 | 197 |
|
187 |
| -func Benchmark_Decode_MediumStruct_Unmarshal_GoJay(b *testing.B) { |
| 198 | +func Benchmark_Decode_MediumStruct_Unmarshal_SegmentioJson(b *testing.B) { |
| 199 | + b.ReportAllocs() |
| 200 | + for i := 0; i < b.N; i++ { |
| 201 | + result := MediumPayload{} |
| 202 | + if err := segmentiojson.Unmarshal(MediumFixture, &result); err != nil { |
| 203 | + b.Fatal(err) |
| 204 | + } |
| 205 | + } |
| 206 | +} |
| 207 | + |
| 208 | +func Benchmark_Decode_MediumStruct_Unmarshal_JsonIter(b *testing.B) { |
188 | 209 | b.ReportAllocs()
|
189 | 210 | for n := 0; n < b.N; n++ {
|
190 | 211 | result := MediumPayload{}
|
191 |
| - if err := gojay.UnmarshalJSONObject(MediumFixture, &result); err != nil { |
| 212 | + if err := jsoniter.Unmarshal(MediumFixture, &result); err != nil { |
192 | 213 | b.Fatal(err)
|
193 | 214 | }
|
194 | 215 | }
|
195 | 216 | }
|
196 | 217 |
|
197 |
| -func Benchmark_Decode_MediumStruct_Unmarshal_GoJayUnsafe(b *testing.B) { |
| 218 | +func Benchmark_Decode_MediumStruct_Unmarshal_GoJay(b *testing.B) { |
198 | 219 | b.ReportAllocs()
|
199 |
| - for i := 0; i < b.N; i++ { |
| 220 | + for n := 0; n < b.N; n++ { |
200 | 221 | result := MediumPayload{}
|
201 |
| - if err := gojay.Unsafe.UnmarshalJSONObject(MediumFixture, &result); err != nil { |
| 222 | + if err := gojay.UnmarshalJSONObject(MediumFixture, &result); err != nil { |
202 | 223 | b.Fatal(err)
|
203 | 224 | }
|
204 | 225 | }
|
205 | 226 | }
|
206 | 227 |
|
207 |
| -func Benchmark_Decode_MediumStruct_Unmarshal_SegmentioJson(b *testing.B) { |
| 228 | +func Benchmark_Decode_MediumStruct_Unmarshal_GoJayUnsafe(b *testing.B) { |
208 | 229 | b.ReportAllocs()
|
209 | 230 | for i := 0; i < b.N; i++ {
|
210 | 231 | result := MediumPayload{}
|
211 |
| - if err := segmentiojson.Unmarshal(MediumFixture, &result); err != nil { |
| 232 | + if err := gojay.Unsafe.UnmarshalJSONObject(MediumFixture, &result); err != nil { |
212 | 233 | b.Fatal(err)
|
213 | 234 | }
|
214 | 235 | }
|
@@ -246,37 +267,37 @@ func Benchmark_Decode_MediumStruct_Stream_EncodingJson(b *testing.B) {
|
246 | 267 | }
|
247 | 268 | }
|
248 | 269 |
|
249 |
| -func Benchmark_Decode_MediumStruct_Stream_JsonIter(b *testing.B) { |
| 270 | +func Benchmark_Decode_MediumStruct_Stream_SegmentioJson(b *testing.B) { |
250 | 271 | b.ReportAllocs()
|
251 | 272 | reader := bytes.NewReader(MediumFixture)
|
252 |
| - for i := 0; i < b.N; i++ { |
253 |
| - result := MediumPayload{} |
| 273 | + for n := 0; n < b.N; n++ { |
254 | 274 | reader.Reset(MediumFixture)
|
255 |
| - if err := jsoniter.NewDecoder(reader).Decode(&result); err != nil { |
| 275 | + result := MediumPayload{} |
| 276 | + if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil { |
256 | 277 | b.Fatal(err)
|
257 | 278 | }
|
258 | 279 | }
|
259 | 280 | }
|
260 | 281 |
|
261 |
| -func Benchmark_Decode_MediumStruct_Stream_GoJay(b *testing.B) { |
| 282 | +func Benchmark_Decode_MediumStruct_Stream_JsonIter(b *testing.B) { |
262 | 283 | b.ReportAllocs()
|
263 | 284 | reader := bytes.NewReader(MediumFixture)
|
264 |
| - for n := 0; n < b.N; n++ { |
265 |
| - reader.Reset(MediumFixture) |
| 285 | + for i := 0; i < b.N; i++ { |
266 | 286 | result := MediumPayload{}
|
267 |
| - if err := gojay.NewDecoder(reader).DecodeObject(&result); err != nil { |
| 287 | + reader.Reset(MediumFixture) |
| 288 | + if err := jsoniter.NewDecoder(reader).Decode(&result); err != nil { |
268 | 289 | b.Fatal(err)
|
269 | 290 | }
|
270 | 291 | }
|
271 | 292 | }
|
272 | 293 |
|
273 |
| -func Benchmark_Decode_MediumStruct_Stream_SegmentioJson(b *testing.B) { |
| 294 | +func Benchmark_Decode_MediumStruct_Stream_GoJay(b *testing.B) { |
274 | 295 | b.ReportAllocs()
|
275 | 296 | reader := bytes.NewReader(MediumFixture)
|
276 | 297 | for n := 0; n < b.N; n++ {
|
277 | 298 | reader.Reset(MediumFixture)
|
278 | 299 | result := MediumPayload{}
|
279 |
| - if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil { |
| 300 | + if err := gojay.NewDecoder(reader).DecodeObject(&result); err != nil { |
280 | 301 | b.Fatal(err)
|
281 | 302 | }
|
282 | 303 | }
|
@@ -315,41 +336,51 @@ func Benchmark_Decode_LargeStruct_Unmarshal_FastJson(b *testing.B) {
|
315 | 336 | }
|
316 | 337 | }
|
317 | 338 |
|
318 |
| -func Benchmark_Decode_LargeStruct_Unmarshal_JsonIter(b *testing.B) { |
| 339 | +func Benchmark_Decode_LargeStruct_Unmarshal_Sonic(b *testing.B) { |
319 | 340 | b.ReportAllocs()
|
320 | 341 | for n := 0; n < b.N; n++ {
|
321 | 342 | result := LargePayload{}
|
322 |
| - if err := jsoniter.Unmarshal(LargeFixture, &result); err != nil { |
| 343 | + if err := sonic.Unmarshal(LargeFixture, &result); err != nil { |
323 | 344 | b.Fatal(err)
|
324 | 345 | }
|
325 | 346 | }
|
326 | 347 | }
|
327 | 348 |
|
328 |
| -func Benchmark_Decode_LargeStruct_Unmarshal_GoJay(b *testing.B) { |
| 349 | +func Benchmark_Decode_LargeStruct_Unmarshal_SegmentioJson(b *testing.B) { |
| 350 | + b.ReportAllocs() |
| 351 | + for i := 0; i < b.N; i++ { |
| 352 | + result := LargePayload{} |
| 353 | + if err := segmentiojson.Unmarshal(LargeFixture, &result); err != nil { |
| 354 | + b.Fatal(err) |
| 355 | + } |
| 356 | + } |
| 357 | +} |
| 358 | + |
| 359 | +func Benchmark_Decode_LargeStruct_Unmarshal_JsonIter(b *testing.B) { |
329 | 360 | b.ReportAllocs()
|
330 | 361 | for n := 0; n < b.N; n++ {
|
331 | 362 | result := LargePayload{}
|
332 |
| - if err := gojay.UnmarshalJSONObject(LargeFixture, &result); err != nil { |
| 363 | + if err := jsoniter.Unmarshal(LargeFixture, &result); err != nil { |
333 | 364 | b.Fatal(err)
|
334 | 365 | }
|
335 | 366 | }
|
336 | 367 | }
|
337 | 368 |
|
338 |
| -func Benchmark_Decode_LargeStruct_Unmarshal_GoJayUnsafe(b *testing.B) { |
| 369 | +func Benchmark_Decode_LargeStruct_Unmarshal_GoJay(b *testing.B) { |
339 | 370 | b.ReportAllocs()
|
340 |
| - for i := 0; i < b.N; i++ { |
| 371 | + for n := 0; n < b.N; n++ { |
341 | 372 | result := LargePayload{}
|
342 |
| - if err := gojay.Unsafe.UnmarshalJSONObject(LargeFixture, &result); err != nil { |
| 373 | + if err := gojay.UnmarshalJSONObject(LargeFixture, &result); err != nil { |
343 | 374 | b.Fatal(err)
|
344 | 375 | }
|
345 | 376 | }
|
346 | 377 | }
|
347 | 378 |
|
348 |
| -func Benchmark_Decode_LargeStruct_Unmarshal_SegmentioJson(b *testing.B) { |
| 379 | +func Benchmark_Decode_LargeStruct_Unmarshal_GoJayUnsafe(b *testing.B) { |
349 | 380 | b.ReportAllocs()
|
350 | 381 | for i := 0; i < b.N; i++ {
|
351 | 382 | result := LargePayload{}
|
352 |
| - if err := segmentiojson.Unmarshal(LargeFixture, &result); err != nil { |
| 383 | + if err := gojay.Unsafe.UnmarshalJSONObject(LargeFixture, &result); err != nil { |
353 | 384 | b.Fatal(err)
|
354 | 385 | }
|
355 | 386 | }
|
@@ -415,37 +446,37 @@ func Benchmark_Decode_LargeStruct_Stream_EncodingJson(b *testing.B) {
|
415 | 446 | }
|
416 | 447 | }
|
417 | 448 |
|
418 |
| -func Benchmark_Decode_LargeStruct_Stream_JsonIter(b *testing.B) { |
| 449 | +func Benchmark_Decode_LargeStruct_Stream_SegmentioJson(b *testing.B) { |
419 | 450 | b.ReportAllocs()
|
420 | 451 | reader := bytes.NewReader(LargeFixture)
|
421 | 452 | for i := 0; i < b.N; i++ {
|
422 | 453 | result := LargePayload{}
|
423 | 454 | reader.Reset(LargeFixture)
|
424 |
| - if err := jsoniter.NewDecoder(reader).Decode(&result); err != nil { |
| 455 | + if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil { |
425 | 456 | b.Fatal(err)
|
426 | 457 | }
|
427 | 458 | }
|
428 | 459 | }
|
429 | 460 |
|
430 |
| -func Benchmark_Decode_LargeStruct_Stream_GoJay(b *testing.B) { |
| 461 | +func Benchmark_Decode_LargeStruct_Stream_JsonIter(b *testing.B) { |
431 | 462 | b.ReportAllocs()
|
432 | 463 | reader := bytes.NewReader(LargeFixture)
|
433 |
| - for n := 0; n < b.N; n++ { |
434 |
| - reader.Reset(LargeFixture) |
| 464 | + for i := 0; i < b.N; i++ { |
435 | 465 | result := LargePayload{}
|
436 |
| - if err := gojay.NewDecoder(reader).DecodeObject(&result); err != nil { |
| 466 | + reader.Reset(LargeFixture) |
| 467 | + if err := jsoniter.NewDecoder(reader).Decode(&result); err != nil { |
437 | 468 | b.Fatal(err)
|
438 | 469 | }
|
439 | 470 | }
|
440 | 471 | }
|
441 | 472 |
|
442 |
| -func Benchmark_Decode_LargeStruct_Stream_SegmentioJson(b *testing.B) { |
| 473 | +func Benchmark_Decode_LargeStruct_Stream_GoJay(b *testing.B) { |
443 | 474 | b.ReportAllocs()
|
444 | 475 | reader := bytes.NewReader(LargeFixture)
|
445 |
| - for i := 0; i < b.N; i++ { |
446 |
| - result := LargePayload{} |
| 476 | + for n := 0; n < b.N; n++ { |
447 | 477 | reader.Reset(LargeFixture)
|
448 |
| - if err := segmentiojson.NewDecoder(reader).Decode(&result); err != nil { |
| 478 | + result := LargePayload{} |
| 479 | + if err := gojay.NewDecoder(reader).DecodeObject(&result); err != nil { |
449 | 480 | b.Fatal(err)
|
450 | 481 | }
|
451 | 482 | }
|
|
0 commit comments