|
@@ -98,24 +98,26 @@ func TestBenchInit(t *testing.T) {
|
|
|
if !testing.Verbose() {
|
|
if !testing.Verbose() {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- // logTv(t, "..............................................")
|
|
|
|
|
- logT(t, "BENCHMARK INIT: %v", time.Now())
|
|
|
|
|
- // logTv(t, "To run full benchmark comparing encodings, use: \"go test -bench=.\"")
|
|
|
|
|
- logT(t, "Benchmark: ")
|
|
|
|
|
- logT(t, "\tStruct recursive Depth: %d", testDepth)
|
|
|
|
|
|
|
+ // t.Logf("..............................................")
|
|
|
|
|
+ t.Logf("BENCHMARK INIT: %v", time.Now())
|
|
|
|
|
+ // t.Logf("To run full benchmark comparing encodings, use: \"go test -bench=.\"")
|
|
|
|
|
+ t.Logf("Benchmark: ")
|
|
|
|
|
+ t.Logf("\tStruct recursive Depth: %d", testDepth)
|
|
|
if approxSize > 0 {
|
|
if approxSize > 0 {
|
|
|
- logT(t, "\tApproxDeepSize Of benchmark Struct: %d bytes", approxSize)
|
|
|
|
|
|
|
+ t.Logf("\tApproxDeepSize Of benchmark Struct: %d bytes", approxSize)
|
|
|
}
|
|
}
|
|
|
if benchUnscientificRes {
|
|
if benchUnscientificRes {
|
|
|
- logT(t, "Benchmark One-Pass Run (with Unscientific Encode/Decode times): ")
|
|
|
|
|
|
|
+ t.Logf("Benchmark One-Pass Run (with Unscientific Encode/Decode times): ")
|
|
|
} else {
|
|
} else {
|
|
|
- logT(t, "Benchmark One-Pass Run:")
|
|
|
|
|
|
|
+ t.Logf("Benchmark One-Pass Run:")
|
|
|
}
|
|
}
|
|
|
for _, bc := range benchCheckers {
|
|
for _, bc := range benchCheckers {
|
|
|
doBenchCheck(t, bc.name, bc.encodefn, bc.decodefn)
|
|
doBenchCheck(t, bc.name, bc.encodefn, bc.decodefn)
|
|
|
}
|
|
}
|
|
|
- logTv(t, "..............................................")
|
|
|
|
|
- logTv(t, "<<<<====>>>> depth: %v, ts: %#v\n", testDepth, benchTs)
|
|
|
|
|
|
|
+ if testVerbose {
|
|
|
|
|
+ t.Logf("..............................................")
|
|
|
|
|
+ t.Logf("<<<<====>>>> depth: %v, ts: %#v\n", testDepth, benchTs)
|
|
|
|
|
+ }
|
|
|
runtime.GC()
|
|
runtime.GC()
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
}
|
|
}
|
|
@@ -130,37 +132,45 @@ func fnBenchNewTs() interface{} {
|
|
|
|
|
|
|
|
// const benchCheckDoDeepEqual = false
|
|
// const benchCheckDoDeepEqual = false
|
|
|
|
|
|
|
|
-func benchRecoverPanic(t interface{}) {
|
|
|
|
|
|
|
+func benchRecoverPanic(t *testing.B) {
|
|
|
|
|
+ if benchRecover {
|
|
|
|
|
+ if r := recover(); r != nil {
|
|
|
|
|
+ t.Logf("(recovered) panic: %v\n", r)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func benchRecoverPanicT(t *testing.T) {
|
|
|
if benchRecover {
|
|
if benchRecover {
|
|
|
if r := recover(); r != nil {
|
|
if r := recover(); r != nil {
|
|
|
- logT(t, "(recovered) panic: %v\n", r)
|
|
|
|
|
|
|
+ t.Logf("(recovered) panic: %v\n", r)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func doBenchCheck(t *testing.T, name string, encfn benchEncFn, decfn benchDecFn) {
|
|
func doBenchCheck(t *testing.T, name string, encfn benchEncFn, decfn benchDecFn) {
|
|
|
// if benchUnscientificRes {
|
|
// if benchUnscientificRes {
|
|
|
- // logTv(t, "-------------- %s ----------------", name)
|
|
|
|
|
|
|
+ // t.Logf("-------------- %s ----------------", name)
|
|
|
// }
|
|
// }
|
|
|
- defer benchRecoverPanic(t)
|
|
|
|
|
|
|
+ defer benchRecoverPanicT(t)
|
|
|
runtime.GC()
|
|
runtime.GC()
|
|
|
tnow := time.Now()
|
|
tnow := time.Now()
|
|
|
buf, err := encfn(benchTs, nil)
|
|
buf, err := encfn(benchTs, nil)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- logT(t, "\t%10s: **** Error encoding benchTs: %v", name, err)
|
|
|
|
|
|
|
+ t.Logf("\t%10s: **** Error encoding benchTs: %v", name, err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
encDur := time.Since(tnow)
|
|
encDur := time.Since(tnow)
|
|
|
encLen := len(buf)
|
|
encLen := len(buf)
|
|
|
runtime.GC()
|
|
runtime.GC()
|
|
|
if !benchUnscientificRes {
|
|
if !benchUnscientificRes {
|
|
|
- logT(t, "\t%10s: len: %d bytes\n", name, encLen)
|
|
|
|
|
|
|
+ t.Logf("\t%10s: len: %d bytes\n", name, encLen)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
tnow = time.Now()
|
|
tnow = time.Now()
|
|
|
var ts2 TestStruc
|
|
var ts2 TestStruc
|
|
|
if err = decfn(buf, &ts2); err != nil {
|
|
if err = decfn(buf, &ts2); err != nil {
|
|
|
- logT(t, "\t%10s: **** Error decoding into new TestStruc: %v", name, err)
|
|
|
|
|
|
|
+ t.Logf("\t%10s: **** Error decoding into new TestStruc: %v", name, err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
decDur := time.Since(tnow)
|
|
decDur := time.Since(tnow)
|
|
@@ -168,9 +178,9 @@ func doBenchCheck(t *testing.T, name string, encfn benchEncFn, decfn benchDecFn)
|
|
|
if benchVerify {
|
|
if benchVerify {
|
|
|
err = deepEqual(benchTs, &ts2)
|
|
err = deepEqual(benchTs, &ts2)
|
|
|
if err == nil {
|
|
if err == nil {
|
|
|
- logT(t, "\t%10s: len: %d bytes,\t encode: %v,\t decode: %v,\tencoded == decoded", name, encLen, encDur, decDur)
|
|
|
|
|
|
|
+ t.Logf("\t%10s: len: %d bytes,\t encode: %v,\t decode: %v,\tencoded == decoded", name, encLen, encDur, decDur)
|
|
|
} else {
|
|
} else {
|
|
|
- logT(t, "\t%10s: len: %d bytes,\t encode: %v,\t decode: %v,\tencoded != decoded: %v", name, encLen, encDur, decDur, err)
|
|
|
|
|
|
|
+ t.Logf("\t%10s: len: %d bytes,\t encode: %v,\t decode: %v,\tencoded != decoded: %v", name, encLen, encDur, decDur, err)
|
|
|
// if benchShowJsonOnError && strings.Contains(name, "json") {
|
|
// if benchShowJsonOnError && strings.Contains(name, "json") {
|
|
|
// fmt.Printf("\n\n%s\n\n", buf)
|
|
// fmt.Printf("\n\n%s\n\n", buf)
|
|
|
// //fmt.Printf("\n\n%#v\n\n", benchTs)
|
|
// //fmt.Printf("\n\n%#v\n\n", benchTs)
|
|
@@ -196,16 +206,16 @@ func doBenchCheck(t *testing.T, name string, encfn benchEncFn, decfn benchDecFn)
|
|
|
// f2.Close()
|
|
// f2.Close()
|
|
|
// f3.Close()
|
|
// f3.Close()
|
|
|
// }
|
|
// }
|
|
|
- // logT(t, "\t: err: %v,\n benchTs: %#v\n\n, ts2: %#v\n\n", err, benchTs, ts2) // TODO: remove
|
|
|
|
|
- // logT(t, "BenchVerify: Error comparing en|decoded TestStruc: %v", err)
|
|
|
|
|
|
|
+ // t.Logf("\t: err: %v,\n benchTs: %#v\n\n, ts2: %#v\n\n", err, benchTs, ts2) // TODO: remove
|
|
|
|
|
+ // t.Logf("BenchVerify: Error comparing en|decoded TestStruc: %v", err)
|
|
|
// return
|
|
// return
|
|
|
- // logT(t, "BenchVerify: Error comparing benchTs: %v\n--------\n%v\n--------\n%v", err, benchTs, ts2)
|
|
|
|
|
|
|
+ // t.Logf("BenchVerify: Error comparing benchTs: %v\n--------\n%v\n--------\n%v", err, benchTs, ts2)
|
|
|
// if strings.Contains(name, "json") {
|
|
// if strings.Contains(name, "json") {
|
|
|
- // logT(t, "\n\tDECODED FROM\n--------\n%s", buf)
|
|
|
|
|
|
|
+ // t.Logf("\n\tDECODED FROM\n--------\n%s", buf)
|
|
|
// }
|
|
// }
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
- logT(t, "\t%10s: len: %d bytes,\t encode: %v,\t decode: %v", name, encLen, encDur, decDur)
|
|
|
|
|
|
|
+ t.Logf("\t%10s: len: %d bytes,\t encode: %v,\t decode: %v", name, encLen, encDur, decDur)
|
|
|
}
|
|
}
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
@@ -223,7 +233,8 @@ func fnBenchmarkEncode(b *testing.B, encName string, ts interface{}, encfn bench
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- failT(b, "Error encoding benchTs: %s: %v", encName, err)
|
|
|
|
|
|
|
+ b.Logf("Error encoding benchTs: %s: %v", encName, err)
|
|
|
|
|
+ b.FailNow()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -235,7 +246,8 @@ func fnBenchmarkDecode(b *testing.B, encName string, ts interface{},
|
|
|
bs := make([]byte, 0, approxSize)
|
|
bs := make([]byte, 0, approxSize)
|
|
|
buf, err := encfn(ts, bs)
|
|
buf, err := encfn(ts, bs)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- failT(b, "Error encoding benchTs: %s: %v", encName, err)
|
|
|
|
|
|
|
+ b.Logf("Error encoding benchTs: %s: %v", encName, err)
|
|
|
|
|
+ b.FailNow()
|
|
|
}
|
|
}
|
|
|
// if false && benchVerify { // do not do benchVerify during decode
|
|
// if false && benchVerify { // do not do benchVerify during decode
|
|
|
// // ts2 := newfn()
|
|
// // ts2 := newfn()
|
|
@@ -257,6 +269,7 @@ func fnBenchmarkDecode(b *testing.B, encName string, ts interface{},
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- failT(b, "Error decoding into new TestStruc: %s: %v", encName, err)
|
|
|
|
|
|
|
+ b.Logf("Error decoding into new TestStruc: %s: %v", encName, err)
|
|
|
|
|
+ b.FailNow()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|