@@ -13,8 +13,8 @@ import (
13
13
"testing"
14
14
"time"
15
15
16
- "github.com/ohler55/ojg"
17
16
"github.com/ohler55/ojg/gen"
17
+ "github.com/ohler55/ojg/oj"
18
18
19
19
"gitlab.com/uhn/core/pkg/tree"
20
20
)
@@ -120,8 +120,8 @@ func jsonBenchmarks(base testing.BenchmarkResult, indent, sort bool) {
120
120
fmt .Printf ("JSON() benchmarks, indent: %t, sort: %t\n " , indent , sort )
121
121
122
122
var treeRes testing.BenchmarkResult
123
- var ojgSRes testing.BenchmarkResult
124
- var ojgWRes testing.BenchmarkResult
123
+ var ojSRes testing.BenchmarkResult
124
+ var ojWRes testing.BenchmarkResult
125
125
126
126
if sort {
127
127
treeRes = testing .Benchmark (treeJSONSort )
@@ -137,34 +137,34 @@ func jsonBenchmarks(base testing.BenchmarkResult, indent, sort bool) {
137
137
treeNs , 1.0 , treeBytes , 1.0 , treeAllocs , 1.0 )
138
138
139
139
if sort {
140
- ojgSRes = testing .Benchmark (ojgStringSort )
140
+ ojSRes = testing .Benchmark (ojStringSort )
141
141
} else if indent {
142
- ojgSRes = testing .Benchmark (ojgString2 )
142
+ ojSRes = testing .Benchmark (ojString2 )
143
143
} else {
144
- ojgSRes = testing .Benchmark (ojgString )
144
+ ojSRes = testing .Benchmark (ojString )
145
145
}
146
- ojgNs := ojgSRes .NsPerOp ()
147
- ojgBytes := ojgSRes .AllocedBytesPerOp ()
148
- ojgAllocs := ojgSRes .AllocsPerOp ()
149
- fmt .Printf (" ojg .String: %6d ns/op (%3.2fx) %6d B/op (%3.2fx) %6d allocs/op (%3.2fx)\n " ,
150
- ojgNs , float64 (treeNs )/ float64 (ojgNs ),
151
- ojgBytes , float64 (treeBytes )/ float64 (ojgBytes ),
152
- ojgAllocs , float64 (treeAllocs )/ float64 (ojgAllocs ))
146
+ ojNs := ojSRes .NsPerOp ()
147
+ ojBytes := ojSRes .AllocedBytesPerOp ()
148
+ ojAllocs := ojSRes .AllocsPerOp ()
149
+ fmt .Printf (" oj .String: %6d ns/op (%3.2fx) %6d B/op (%3.2fx) %6d allocs/op (%3.2fx)\n " ,
150
+ ojNs , float64 (treeNs )/ float64 (ojNs ),
151
+ ojBytes , float64 (treeBytes )/ float64 (ojBytes ),
152
+ ojAllocs , float64 (treeAllocs )/ float64 (ojAllocs ))
153
153
154
154
if sort {
155
- ojgWRes = testing .Benchmark (ojgWriteSort )
155
+ ojWRes = testing .Benchmark (ojWriteSort )
156
156
} else if indent {
157
- ojgWRes = testing .Benchmark (ojgWrite2 )
157
+ ojWRes = testing .Benchmark (ojWrite2 )
158
158
} else {
159
- ojgWRes = testing .Benchmark (ojgWrite )
159
+ ojWRes = testing .Benchmark (ojWrite )
160
160
}
161
- ojgNs = ojgWRes .NsPerOp ()
162
- ojgBytes = ojgWRes .AllocedBytesPerOp ()
163
- ojgAllocs = ojgWRes .AllocsPerOp ()
164
- fmt .Printf (" ojg .Write: %6d ns/op (%3.2fx) %6d B/op (%3.2fx) %6d allocs/op (%3.2fx)\n " ,
165
- ojgNs , float64 (treeNs )/ float64 (ojgNs ),
166
- ojgBytes , float64 (treeBytes )/ float64 (ojgBytes ),
167
- ojgAllocs , float64 (treeAllocs )/ float64 (ojgAllocs ))
161
+ ojNs = ojWRes .NsPerOp ()
162
+ ojBytes = ojWRes .AllocedBytesPerOp ()
163
+ ojAllocs = ojWRes .AllocsPerOp ()
164
+ fmt .Printf (" oj .Write: %6d ns/op (%3.2fx) %6d B/op (%3.2fx) %6d allocs/op (%3.2fx)\n " ,
165
+ ojNs , float64 (treeNs )/ float64 (ojNs ),
166
+ ojBytes , float64 (treeBytes )/ float64 (ojBytes ),
167
+ ojAllocs , float64 (treeAllocs )/ float64 (ojAllocs ))
168
168
}
169
169
170
170
func treeJSON (b * testing.B ) {
@@ -197,71 +197,71 @@ func treeJSONSort(b *testing.B) {
197
197
}
198
198
}
199
199
200
- func ojgString (b * testing.B ) {
200
+ func ojString (b * testing.B ) {
201
201
tm := time .Date (2020 , time .April , 12 , 16 , 34 , 04 , 123456789 , time .UTC )
202
202
data := gen .Alter (benchmarkData (tm ))
203
- opt := ojg .Options {OmitNil : true }
203
+ opt := oj .Options {OmitNil : true }
204
204
b .ResetTimer ()
205
205
for n := 0 ; n < b .N ; n ++ {
206
- _ = ojg .String (data , & opt )
206
+ _ = oj .String (data , & opt )
207
207
}
208
208
}
209
209
210
- func ojgString2 (b * testing.B ) {
210
+ func ojString2 (b * testing.B ) {
211
211
tm := time .Date (2020 , time .April , 12 , 16 , 34 , 04 , 123456789 , time .UTC )
212
212
data := gen .Alter (benchmarkData (tm ))
213
- opt := ojg .Options {OmitNil : true , Indent : 2 }
213
+ opt := oj .Options {OmitNil : true , Indent : 2 }
214
214
b .ResetTimer ()
215
215
for n := 0 ; n < b .N ; n ++ {
216
- _ = ojg .String (data , & opt )
216
+ _ = oj .String (data , & opt )
217
217
}
218
218
}
219
219
220
- func ojgStringSort (b * testing.B ) {
220
+ func ojStringSort (b * testing.B ) {
221
221
tm := time .Date (2020 , time .April , 12 , 16 , 34 , 04 , 123456789 , time .UTC )
222
222
data := gen .Alter (benchmarkData (tm ))
223
- opt := ojg .Options {OmitNil : true , Indent : 2 , Sort : true }
223
+ opt := oj .Options {OmitNil : true , Indent : 2 , Sort : true }
224
224
b .ResetTimer ()
225
225
for n := 0 ; n < b .N ; n ++ {
226
- _ = ojg .String (data , & opt )
226
+ _ = oj .String (data , & opt )
227
227
}
228
228
}
229
229
230
- func ojgWrite (b * testing.B ) {
230
+ func ojWrite (b * testing.B ) {
231
231
tm := time .Date (2020 , time .April , 12 , 16 , 34 , 04 , 123456789 , time .UTC )
232
232
data := gen .Alter (benchmarkData (tm ))
233
- opt := ojg .Options {OmitNil : true }
233
+ opt := oj .Options {OmitNil : true }
234
234
var buf strings.Builder
235
235
b .ResetTimer ()
236
236
for n := 0 ; n < b .N ; n ++ {
237
237
buf .Reset ()
238
- _ = ojg .Write (& buf , data , & opt )
238
+ _ = oj .Write (& buf , data , & opt )
239
239
_ = buf .String ()
240
240
}
241
241
}
242
242
243
- func ojgWrite2 (b * testing.B ) {
243
+ func ojWrite2 (b * testing.B ) {
244
244
tm := time .Date (2020 , time .April , 12 , 16 , 34 , 04 , 123456789 , time .UTC )
245
245
data := gen .Alter (benchmarkData (tm ))
246
- opt := ojg .Options {OmitNil : true , Indent : 2 }
246
+ opt := oj .Options {OmitNil : true , Indent : 2 }
247
247
var buf strings.Builder
248
248
b .ResetTimer ()
249
249
for n := 0 ; n < b .N ; n ++ {
250
250
buf .Reset ()
251
- _ = ojg .Write (& buf , data , & opt )
251
+ _ = oj .Write (& buf , data , & opt )
252
252
_ = buf .String ()
253
253
}
254
254
}
255
255
256
- func ojgWriteSort (b * testing.B ) {
256
+ func ojWriteSort (b * testing.B ) {
257
257
tm := time .Date (2020 , time .April , 12 , 16 , 34 , 04 , 123456789 , time .UTC )
258
258
data := gen .Alter (benchmarkData (tm ))
259
- opt := ojg .Options {OmitNil : true , Indent : 2 , Sort : true }
259
+ opt := oj .Options {OmitNil : true , Indent : 2 , Sort : true }
260
260
var buf strings.Builder
261
261
b .ResetTimer ()
262
262
for n := 0 ; n < b .N ; n ++ {
263
263
buf .Reset ()
264
- _ = ojg .Write (& buf , data , & opt )
264
+ _ = oj .Write (& buf , data , & opt )
265
265
_ = buf .String ()
266
266
}
267
267
}
@@ -277,14 +277,14 @@ func validateBenchmarks() {
277
277
fmt .Printf ("json.Valid: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n " ,
278
278
goNs , 1.0 , goBytes , 1.0 , goAllocs , 1.0 )
279
279
280
- ojgRes := testing .Benchmark (ojgValidate )
281
- ojgNs := ojgRes .NsPerOp ()
282
- ojgBytes := ojgRes .AllocedBytesPerOp ()
283
- ojgAllocs := ojgRes .AllocsPerOp ()
284
- fmt .Printf (" ojg .Validate: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n " ,
285
- ojgNs , float64 (goNs )/ float64 (ojgNs ),
286
- ojgBytes , float64 (goBytes )/ float64 (ojgBytes ),
287
- ojgAllocs , float64 (goAllocs )/ float64 (ojgAllocs ))
280
+ ojRes := testing .Benchmark (ojValidate )
281
+ ojNs := ojRes .NsPerOp ()
282
+ ojBytes := ojRes .AllocedBytesPerOp ()
283
+ ojAllocs := ojRes .AllocsPerOp ()
284
+ fmt .Printf (" oj .Validate: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n " ,
285
+ ojNs , float64 (goNs )/ float64 (ojNs ),
286
+ ojBytes , float64 (goBytes )/ float64 (ojBytes ),
287
+ ojAllocs , float64 (goAllocs )/ float64 (ojAllocs ))
288
288
289
289
treeRes := testing .Benchmark (treeValidate )
290
290
treeNs := treeRes .NsPerOp ()
@@ -302,8 +302,8 @@ func goValidate(b *testing.B) {
302
302
}
303
303
}
304
304
305
- func ojgValidate (b * testing.B ) {
306
- var v ojg .Validator
305
+ func ojValidate (b * testing.B ) {
306
+ var v oj .Validator
307
307
for n := 0 ; n < b .N ; n ++ {
308
308
_ = v .Validate ([]byte (sampleJSON ))
309
309
//err := v.Validate([]byte(sampleJSON))
@@ -330,14 +330,14 @@ func validateReaderBenchmarks() {
330
330
fmt .Printf ("json.Decoder: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n " ,
331
331
goNs , 1.0 , goBytes , 1.0 , goAllocs , 1.0 )
332
332
333
- ojgRes := testing .Benchmark (ojgValidateReader )
334
- ojgNs := ojgRes .NsPerOp () - baseRes .NsPerOp ()
335
- ojgBytes := ojgRes .AllocedBytesPerOp () - baseRes .AllocedBytesPerOp ()
336
- ojgAllocs := ojgRes .AllocsPerOp () - baseRes .AllocsPerOp ()
337
- fmt .Printf (" ojg .ValidateReader: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n " ,
338
- ojgNs , float64 (goNs )/ float64 (ojgNs ),
339
- ojgBytes , float64 (goBytes )/ float64 (ojgBytes ),
340
- ojgAllocs , float64 (goAllocs )/ float64 (ojgAllocs ))
333
+ ojRes := testing .Benchmark (ojValidateReader )
334
+ ojNs := ojRes .NsPerOp () - baseRes .NsPerOp ()
335
+ ojBytes := ojRes .AllocedBytesPerOp () - baseRes .AllocedBytesPerOp ()
336
+ ojAllocs := ojRes .AllocsPerOp () - baseRes .AllocsPerOp ()
337
+ fmt .Printf (" oj .ValidateReader: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n " ,
338
+ ojNs , float64 (goNs )/ float64 (ojNs ),
339
+ ojBytes , float64 (goBytes )/ float64 (ojBytes ),
340
+ ojAllocs , float64 (goAllocs )/ float64 (ojAllocs ))
341
341
342
342
treeRes := testing .Benchmark (treeParseReader )
343
343
treeNs := treeRes .NsPerOp () - baseRes .NsPerOp ()
@@ -383,8 +383,8 @@ func goParseReader(b *testing.B) {
383
383
}
384
384
}
385
385
386
- func ojgValidateReader (b * testing.B ) {
387
- var v ojg .Validator
386
+ func ojValidateReader (b * testing.B ) {
387
+ var v oj .Validator
388
388
f , err := os .Open ("test/sample.json" )
389
389
if err != nil {
390
390
fmt .Printf ("Failed to read test/sample.json. %s\n " , err )
@@ -423,24 +423,26 @@ func parseBenchmarks() {
423
423
fmt .Printf ("json.Unmarshal: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n " ,
424
424
goNs , 1.0 , goBytes , 1.0 , goAllocs , 1.0 )
425
425
426
- ojgRes := testing .Benchmark (ojgParse )
427
- ojgNs := ojgRes .NsPerOp ()
428
- ojgBytes := ojgRes .AllocedBytesPerOp ()
429
- ojgAllocs := ojgRes .AllocsPerOp ()
430
- fmt .Printf (" ojg.Parse: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n " ,
431
- ojgNs , float64 (goNs )/ float64 (ojgNs ),
432
- ojgBytes , float64 (goBytes )/ float64 (ojgBytes ),
433
- ojgAllocs , float64 (goAllocs )/ float64 (ojgAllocs ))
434
-
435
- ojgRes = testing .Benchmark (ojgParseSimple )
436
- ojgNs = ojgRes .NsPerOp ()
437
- ojgBytes = ojgRes .AllocedBytesPerOp ()
438
- ojgAllocs = ojgRes .AllocsPerOp ()
439
- fmt .Printf (" ojg.ParseSimple: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n " ,
440
- ojgNs , float64 (goNs )/ float64 (ojgNs ),
441
- ojgBytes , float64 (goBytes )/ float64 (ojgBytes ),
442
- ojgAllocs , float64 (goAllocs )/ float64 (ojgAllocs ))
443
-
426
+ ojRes := testing .Benchmark (ojParse )
427
+ ojNs := ojRes .NsPerOp ()
428
+ ojBytes := ojRes .AllocedBytesPerOp ()
429
+ ojAllocs := ojRes .AllocsPerOp ()
430
+ fmt .Printf (" oj.Parse: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n " ,
431
+ ojNs , float64 (goNs )/ float64 (ojNs ),
432
+ ojBytes , float64 (goBytes )/ float64 (ojBytes ),
433
+ ojAllocs , float64 (goAllocs )/ float64 (ojAllocs ))
434
+
435
+ // TBD add gen parser
436
+ /*
437
+ ojRes = testing.Benchmark(ojParseSimple)
438
+ ojNs = ojRes.NsPerOp()
439
+ ojBytes = ojRes.AllocedBytesPerOp()
440
+ ojAllocs = ojRes.AllocsPerOp()
441
+ fmt.Printf(" oj.ParseSimple: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n",
442
+ ojNs, float64(goNs)/float64(ojNs),
443
+ ojBytes, float64(goBytes)/float64(ojBytes),
444
+ ojAllocs, float64(goAllocs)/float64(ojAllocs))
445
+ */
444
446
treeRes := testing .Benchmark (treeParse )
445
447
treeNs := treeRes .NsPerOp ()
446
448
treeBytes := treeRes .AllocedBytesPerOp ()
@@ -464,24 +466,26 @@ func parseReaderBenchmarks() {
464
466
fmt .Printf ("json.Decoder: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n " ,
465
467
goNs , 1.0 , goBytes , 1.0 , goAllocs , 1.0 )
466
468
467
- ojgRes := testing .Benchmark (ojgParseReader )
468
- ojgNs := ojgRes .NsPerOp () - baseRes .NsPerOp ()
469
- ojgBytes := ojgRes .AllocedBytesPerOp () - baseRes .AllocedBytesPerOp ()
470
- ojgAllocs := ojgRes .AllocsPerOp () - baseRes .AllocsPerOp ()
471
- fmt .Printf (" ojg.ParseReader: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n " ,
472
- ojgNs , float64 (goNs )/ float64 (ojgNs ),
473
- ojgBytes , float64 (goBytes )/ float64 (ojgBytes ),
474
- ojgAllocs , float64 (goAllocs )/ float64 (ojgAllocs ))
475
-
476
- ojgRes = testing .Benchmark (ojgParseSimpleReader )
477
- ojgNs = ojgRes .NsPerOp () - baseRes .NsPerOp ()
478
- ojgBytes = ojgRes .AllocedBytesPerOp () - baseRes .AllocedBytesPerOp ()
479
- ojgAllocs = ojgRes .AllocsPerOp () - baseRes .AllocsPerOp ()
480
- fmt .Printf (" ojg.ParseSimpleReader: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n " ,
481
- ojgNs , float64 (goNs )/ float64 (ojgNs ),
482
- ojgBytes , float64 (goBytes )/ float64 (ojgBytes ),
483
- ojgAllocs , float64 (goAllocs )/ float64 (ojgAllocs ))
484
-
469
+ ojRes := testing .Benchmark (ojParseReader )
470
+ ojNs := ojRes .NsPerOp () - baseRes .NsPerOp ()
471
+ ojBytes := ojRes .AllocedBytesPerOp () - baseRes .AllocedBytesPerOp ()
472
+ ojAllocs := ojRes .AllocsPerOp () - baseRes .AllocsPerOp ()
473
+ fmt .Printf (" oj.ParseReader: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n " ,
474
+ ojNs , float64 (goNs )/ float64 (ojNs ),
475
+ ojBytes , float64 (goBytes )/ float64 (ojBytes ),
476
+ ojAllocs , float64 (goAllocs )/ float64 (ojAllocs ))
477
+
478
+ // TBD add gen parser
479
+ /*
480
+ ojRes = testing.Benchmark(ojParseSimpleReader)
481
+ ojNs = ojRes.NsPerOp() - baseRes.NsPerOp()
482
+ ojBytes = ojRes.AllocedBytesPerOp() - baseRes.AllocedBytesPerOp()
483
+ ojAllocs = ojRes.AllocsPerOp() - baseRes.AllocsPerOp()
484
+ fmt.Printf(" oj.ParseSimpleReader: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n",
485
+ ojNs, float64(goNs)/float64(ojNs),
486
+ ojBytes, float64(goBytes)/float64(ojBytes),
487
+ ojAllocs, float64(goAllocs)/float64(ojAllocs))
488
+ */
485
489
treeRes := testing .Benchmark (treeParseReader )
486
490
treeNs := treeRes .NsPerOp () - baseRes .NsPerOp ()
487
491
treeBytes := treeRes .AllocedBytesPerOp () - baseRes .AllocedBytesPerOp ()
@@ -492,8 +496,8 @@ func parseReaderBenchmarks() {
492
496
treeAllocs , float64 (goAllocs )/ float64 (treeAllocs ))
493
497
}
494
498
495
- func ojgParseReader (b * testing.B ) {
496
- var p ojg .Parser
499
+ func ojParseReader (b * testing.B ) {
500
+ var p oj .Parser
497
501
f , err := os .Open ("test/sample.json" )
498
502
if err != nil {
499
503
fmt .Printf ("Failed to read test/sample.json. %s\n " , err )
@@ -508,8 +512,9 @@ func ojgParseReader(b *testing.B) {
508
512
}
509
513
}
510
514
511
- func ojgParseSimpleReader (b * testing.B ) {
512
- var p ojg.Parser
515
+ /*
516
+ func ojParseSimpleReader(b *testing.B) {
517
+ var p oj.Parser
513
518
f, err := os.Open("test/sample.json")
514
519
if err != nil {
515
520
fmt.Printf("Failed to read test/sample.json. %s\n", err)
@@ -518,11 +523,12 @@ func ojgParseSimpleReader(b *testing.B) {
518
523
defer func() { _ = f.Close() }()
519
524
for n := 0; n < b.N; n++ {
520
525
_, _ = f.Seek(0, 0)
521
- _ , _ = p .ParseSimpleReader (f )
526
+ _, _ = p.ParseReader (f)
522
527
//_, err = p.ParseReader(f)
523
528
//fmt.Println(err)
524
529
}
525
530
}
531
+ */
526
532
527
533
func goParse (b * testing.B ) {
528
534
var result interface {}
@@ -531,23 +537,25 @@ func goParse(b *testing.B) {
531
537
}
532
538
}
533
539
534
- func ojgParse (b * testing.B ) {
535
- p := & ojg .Parser {}
540
+ func ojParse (b * testing.B ) {
541
+ p := & oj .Parser {}
536
542
for n := 0 ; n < b .N ; n ++ {
537
543
_ , _ = p .Parse ([]byte (sampleJSON ))
538
544
//_, err := p.Parse([]byte(sampleJSON))
539
545
//fmt.Println(err)
540
546
}
541
547
}
542
548
543
- func ojgParseSimple (b * testing.B ) {
544
- p := & ojg.Parser {}
549
+ /*
550
+ func ojParseSimple(b *testing.B) {
551
+ p := &oj.Parser{}
545
552
for n := 0; n < b.N; n++ {
546
- _ , _ = p .ParseSimple ([]byte (sampleJSON ))
553
+ _, _ = p.Parse ([]byte(sampleJSON))
547
554
//_, err := p.Parse([]byte(sampleJSON))
548
555
//fmt.Println(err)
549
556
}
550
557
}
558
+ */
551
559
552
560
func treeParse (b * testing.B ) {
553
561
for n := 0 ; n < b .N ; n ++ {
0 commit comments