Skip to content

Commit d8783ae

Browse files
committed
reorg
1 parent 45c8375 commit d8783ae

29 files changed

+1257
-420
lines changed

cmd/benchmarks/main.go

+115-107
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"testing"
1414
"time"
1515

16-
"github.com/ohler55/ojg"
1716
"github.com/ohler55/ojg/gen"
17+
"github.com/ohler55/ojg/oj"
1818

1919
"gitlab.com/uhn/core/pkg/tree"
2020
)
@@ -120,8 +120,8 @@ func jsonBenchmarks(base testing.BenchmarkResult, indent, sort bool) {
120120
fmt.Printf("JSON() benchmarks, indent: %t, sort: %t\n", indent, sort)
121121

122122
var treeRes testing.BenchmarkResult
123-
var ojgSRes testing.BenchmarkResult
124-
var ojgWRes testing.BenchmarkResult
123+
var ojSRes testing.BenchmarkResult
124+
var ojWRes testing.BenchmarkResult
125125

126126
if sort {
127127
treeRes = testing.Benchmark(treeJSONSort)
@@ -137,34 +137,34 @@ func jsonBenchmarks(base testing.BenchmarkResult, indent, sort bool) {
137137
treeNs, 1.0, treeBytes, 1.0, treeAllocs, 1.0)
138138

139139
if sort {
140-
ojgSRes = testing.Benchmark(ojgStringSort)
140+
ojSRes = testing.Benchmark(ojStringSort)
141141
} else if indent {
142-
ojgSRes = testing.Benchmark(ojgString2)
142+
ojSRes = testing.Benchmark(ojString2)
143143
} else {
144-
ojgSRes = testing.Benchmark(ojgString)
144+
ojSRes = testing.Benchmark(ojString)
145145
}
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))
153153

154154
if sort {
155-
ojgWRes = testing.Benchmark(ojgWriteSort)
155+
ojWRes = testing.Benchmark(ojWriteSort)
156156
} else if indent {
157-
ojgWRes = testing.Benchmark(ojgWrite2)
157+
ojWRes = testing.Benchmark(ojWrite2)
158158
} else {
159-
ojgWRes = testing.Benchmark(ojgWrite)
159+
ojWRes = testing.Benchmark(ojWrite)
160160
}
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))
168168
}
169169

170170
func treeJSON(b *testing.B) {
@@ -197,71 +197,71 @@ func treeJSONSort(b *testing.B) {
197197
}
198198
}
199199

200-
func ojgString(b *testing.B) {
200+
func ojString(b *testing.B) {
201201
tm := time.Date(2020, time.April, 12, 16, 34, 04, 123456789, time.UTC)
202202
data := gen.Alter(benchmarkData(tm))
203-
opt := ojg.Options{OmitNil: true}
203+
opt := oj.Options{OmitNil: true}
204204
b.ResetTimer()
205205
for n := 0; n < b.N; n++ {
206-
_ = ojg.String(data, &opt)
206+
_ = oj.String(data, &opt)
207207
}
208208
}
209209

210-
func ojgString2(b *testing.B) {
210+
func ojString2(b *testing.B) {
211211
tm := time.Date(2020, time.April, 12, 16, 34, 04, 123456789, time.UTC)
212212
data := gen.Alter(benchmarkData(tm))
213-
opt := ojg.Options{OmitNil: true, Indent: 2}
213+
opt := oj.Options{OmitNil: true, Indent: 2}
214214
b.ResetTimer()
215215
for n := 0; n < b.N; n++ {
216-
_ = ojg.String(data, &opt)
216+
_ = oj.String(data, &opt)
217217
}
218218
}
219219

220-
func ojgStringSort(b *testing.B) {
220+
func ojStringSort(b *testing.B) {
221221
tm := time.Date(2020, time.April, 12, 16, 34, 04, 123456789, time.UTC)
222222
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}
224224
b.ResetTimer()
225225
for n := 0; n < b.N; n++ {
226-
_ = ojg.String(data, &opt)
226+
_ = oj.String(data, &opt)
227227
}
228228
}
229229

230-
func ojgWrite(b *testing.B) {
230+
func ojWrite(b *testing.B) {
231231
tm := time.Date(2020, time.April, 12, 16, 34, 04, 123456789, time.UTC)
232232
data := gen.Alter(benchmarkData(tm))
233-
opt := ojg.Options{OmitNil: true}
233+
opt := oj.Options{OmitNil: true}
234234
var buf strings.Builder
235235
b.ResetTimer()
236236
for n := 0; n < b.N; n++ {
237237
buf.Reset()
238-
_ = ojg.Write(&buf, data, &opt)
238+
_ = oj.Write(&buf, data, &opt)
239239
_ = buf.String()
240240
}
241241
}
242242

243-
func ojgWrite2(b *testing.B) {
243+
func ojWrite2(b *testing.B) {
244244
tm := time.Date(2020, time.April, 12, 16, 34, 04, 123456789, time.UTC)
245245
data := gen.Alter(benchmarkData(tm))
246-
opt := ojg.Options{OmitNil: true, Indent: 2}
246+
opt := oj.Options{OmitNil: true, Indent: 2}
247247
var buf strings.Builder
248248
b.ResetTimer()
249249
for n := 0; n < b.N; n++ {
250250
buf.Reset()
251-
_ = ojg.Write(&buf, data, &opt)
251+
_ = oj.Write(&buf, data, &opt)
252252
_ = buf.String()
253253
}
254254
}
255255

256-
func ojgWriteSort(b *testing.B) {
256+
func ojWriteSort(b *testing.B) {
257257
tm := time.Date(2020, time.April, 12, 16, 34, 04, 123456789, time.UTC)
258258
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}
260260
var buf strings.Builder
261261
b.ResetTimer()
262262
for n := 0; n < b.N; n++ {
263263
buf.Reset()
264-
_ = ojg.Write(&buf, data, &opt)
264+
_ = oj.Write(&buf, data, &opt)
265265
_ = buf.String()
266266
}
267267
}
@@ -277,14 +277,14 @@ func validateBenchmarks() {
277277
fmt.Printf("json.Valid: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n",
278278
goNs, 1.0, goBytes, 1.0, goAllocs, 1.0)
279279

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))
288288

289289
treeRes := testing.Benchmark(treeValidate)
290290
treeNs := treeRes.NsPerOp()
@@ -302,8 +302,8 @@ func goValidate(b *testing.B) {
302302
}
303303
}
304304

305-
func ojgValidate(b *testing.B) {
306-
var v ojg.Validator
305+
func ojValidate(b *testing.B) {
306+
var v oj.Validator
307307
for n := 0; n < b.N; n++ {
308308
_ = v.Validate([]byte(sampleJSON))
309309
//err := v.Validate([]byte(sampleJSON))
@@ -330,14 +330,14 @@ func validateReaderBenchmarks() {
330330
fmt.Printf("json.Decoder: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n",
331331
goNs, 1.0, goBytes, 1.0, goAllocs, 1.0)
332332

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))
341341

342342
treeRes := testing.Benchmark(treeParseReader)
343343
treeNs := treeRes.NsPerOp() - baseRes.NsPerOp()
@@ -383,8 +383,8 @@ func goParseReader(b *testing.B) {
383383
}
384384
}
385385

386-
func ojgValidateReader(b *testing.B) {
387-
var v ojg.Validator
386+
func ojValidateReader(b *testing.B) {
387+
var v oj.Validator
388388
f, err := os.Open("test/sample.json")
389389
if err != nil {
390390
fmt.Printf("Failed to read test/sample.json. %s\n", err)
@@ -423,24 +423,26 @@ func parseBenchmarks() {
423423
fmt.Printf("json.Unmarshal: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n",
424424
goNs, 1.0, goBytes, 1.0, goAllocs, 1.0)
425425

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+
*/
444446
treeRes := testing.Benchmark(treeParse)
445447
treeNs := treeRes.NsPerOp()
446448
treeBytes := treeRes.AllocedBytesPerOp()
@@ -464,24 +466,26 @@ func parseReaderBenchmarks() {
464466
fmt.Printf("json.Decoder: %6d ns/op (%3.2fx) %6d B/op (%4.2fx) %6d allocs/op (%4.2fx)\n",
465467
goNs, 1.0, goBytes, 1.0, goAllocs, 1.0)
466468

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+
*/
485489
treeRes := testing.Benchmark(treeParseReader)
486490
treeNs := treeRes.NsPerOp() - baseRes.NsPerOp()
487491
treeBytes := treeRes.AllocedBytesPerOp() - baseRes.AllocedBytesPerOp()
@@ -492,8 +496,8 @@ func parseReaderBenchmarks() {
492496
treeAllocs, float64(goAllocs)/float64(treeAllocs))
493497
}
494498

495-
func ojgParseReader(b *testing.B) {
496-
var p ojg.Parser
499+
func ojParseReader(b *testing.B) {
500+
var p oj.Parser
497501
f, err := os.Open("test/sample.json")
498502
if err != nil {
499503
fmt.Printf("Failed to read test/sample.json. %s\n", err)
@@ -508,8 +512,9 @@ func ojgParseReader(b *testing.B) {
508512
}
509513
}
510514

511-
func ojgParseSimpleReader(b *testing.B) {
512-
var p ojg.Parser
515+
/*
516+
func ojParseSimpleReader(b *testing.B) {
517+
var p oj.Parser
513518
f, err := os.Open("test/sample.json")
514519
if err != nil {
515520
fmt.Printf("Failed to read test/sample.json. %s\n", err)
@@ -518,11 +523,12 @@ func ojgParseSimpleReader(b *testing.B) {
518523
defer func() { _ = f.Close() }()
519524
for n := 0; n < b.N; n++ {
520525
_, _ = f.Seek(0, 0)
521-
_, _ = p.ParseSimpleReader(f)
526+
_, _ = p.ParseReader(f)
522527
//_, err = p.ParseReader(f)
523528
//fmt.Println(err)
524529
}
525530
}
531+
*/
526532

527533
func goParse(b *testing.B) {
528534
var result interface{}
@@ -531,23 +537,25 @@ func goParse(b *testing.B) {
531537
}
532538
}
533539

534-
func ojgParse(b *testing.B) {
535-
p := &ojg.Parser{}
540+
func ojParse(b *testing.B) {
541+
p := &oj.Parser{}
536542
for n := 0; n < b.N; n++ {
537543
_, _ = p.Parse([]byte(sampleJSON))
538544
//_, err := p.Parse([]byte(sampleJSON))
539545
//fmt.Println(err)
540546
}
541547
}
542548

543-
func ojgParseSimple(b *testing.B) {
544-
p := &ojg.Parser{}
549+
/*
550+
func ojParseSimple(b *testing.B) {
551+
p := &oj.Parser{}
545552
for n := 0; n < b.N; n++ {
546-
_, _ = p.ParseSimple([]byte(sampleJSON))
553+
_, _ = p.Parse([]byte(sampleJSON))
547554
//_, err := p.Parse([]byte(sampleJSON))
548555
//fmt.Println(err)
549556
}
550557
}
558+
*/
551559

552560
func treeParse(b *testing.B) {
553561
for n := 0; n < b.N; n++ {

0 commit comments

Comments
 (0)