Browse Source

codec: bench: add benchmark very quick suites, and add more benchmark options

Ugorji Nwoke 6 năm trước cách đây
mục cha
commit
b4462fc2f4

+ 34 - 9
codec/bench/bench.sh

@@ -64,12 +64,16 @@ _gen() {
 _suite() {
 _suite() {
     local t="alltests x"
     local t="alltests x"
     local a=( "" "safe"  "notfastpath" "notfastpath safe" "codecgen" "codecgen safe")
     local a=( "" "safe"  "notfastpath" "notfastpath safe" "codecgen" "codecgen safe")
-    local b=( "generated" "generated safe")
     for i in "${a[@]}"
     for i in "${a[@]}"
     do
     do
         echo ">>>> bench TAGS: '$t $i' SUITE: BenchmarkCodecXSuite"
         echo ">>>> bench TAGS: '$t $i' SUITE: BenchmarkCodecXSuite"
         go test -run Nothing -tags "$t $i" -bench BenchmarkCodecXSuite -benchmem "$@"
         go test -run Nothing -tags "$t $i" -bench BenchmarkCodecXSuite -benchmem "$@"
     done
     done
+}
+
+_suite_gen() {
+    local t="alltests x"
+    local b=( "generated" "generated safe")
     for i in "${b[@]}"
     for i in "${b[@]}"
     do
     do
         echo ">>>> bench TAGS: '$t $i' SUITE: BenchmarkCodecXGenSuite"
         echo ">>>> bench TAGS: '$t $i' SUITE: BenchmarkCodecXGenSuite"
@@ -77,25 +81,46 @@ _suite() {
     done
     done
 }
 }
 
 
+_suite_json() {
+    local t="alltests x"
+    local a=( "" "safe"  "notfastpath" "notfastpath safe" "codecgen" "codecgen safe")
+    for i in "${a[@]}"
+    do
+        echo ">>>> bench TAGS: '$t $i' SUITE: BenchmarkCodecQuickAllJsonSuite"
+        go test -run Nothing -tags "$t $i" -bench BenchmarkCodecQuickAllJsonSuite -benchmem "$@"
+    done
+}
+
+_suite_very_quick_json() {
+    echo ">>>> bench TAGS: 'alltests x' SUITE: BenchmarkCodecQuickAllJsonSuite"
+    go test -run Nothing -tags "alltests x" -bench BenchmarkCodecVeryQuickAllJsonSuite -benchmem "$@"
+}
+
 _usage() {
 _usage() {
-    echo "usage: bench.sh -[dcs] for [download, code-generate and suite-of-tests] respectively"
+    echo "usage: bench.sh -[dcsjq] for [download, code-generate, suite-of-tests, json-suite, quick-json-suite] respectively"
 }
 }
 
 
 _main() {
 _main() {
-    if [[ "$1" == "" ]]
+    if [[ "$1" == "" || "$1" == "-h" || "$1" == "-?" ]]
     then
     then
         _usage
         _usage
         return 1
         return 1
     fi
     fi
-    while getopts "dcs" flag
+    local args=()
+    while getopts "dcsjq" flag
     do
     do
-        case "x$flag" in
-            'xd') shift; _go_get "$@" ;;
-            'xc') shift; _gen "$@" ;;
-            'xs') shift; _suite "$@" ;;
-            *) shift; _usage; return 1 ;;
+        case "$flag" in
+            d|c|s|j|q) args+=( "$flag" ) ;;
+            *) _usage; return 1 ;;
         esac
         esac
     done
     done
+    shift "$((OPTIND-1))"
+    
+    [[ " ${args[*]} " == *"d"* ]] && _go_get "$@"
+    [[ " ${args[*]} " == *"c"*  ]] && _gen "$@"
+    [[ " ${args[*]} " == *"s"* ]] && _suite "$@" && _suite_gen "$@" 
+    [[ " ${args[*]} " == *"j"* ]] && _suite_json "$@"
+    [[ " ${args[*]} " == *"q"* ]] && _suite_very_quick_json "$@"
     # shift $((OPTIND-1))
     # shift $((OPTIND-1))
 }
 }
 
 

+ 9 - 6
codec/bench/z_all_bench_test.go

@@ -149,11 +149,9 @@ func benchmarkSuite(t *testing.B, fns ...func(t *testing.B)) {
 	// benchVerify = false
 	// benchVerify = false
 }
 }
 
 
-func benchmarkQuickSuite(t *testing.B, name string, fns ...func(t *testing.B)) {
+func benchmarkVeryQuickSuite(t *testing.B, name string, fns ...func(t *testing.B)) {
 	benchmarkDivider()
 	benchmarkDivider()
 	benchmarkGroupOnce.Do(benchmarkGroupInitAll)
 	benchmarkGroupOnce.Do(benchmarkGroupInitAll)
-	f := benchmarkOneFn(fns)
-
 	benchmarkGroupReset()
 	benchmarkGroupReset()
 
 
 	// bd=1 2 | ti=-1, 1024 |
 	// bd=1 2 | ti=-1, 1024 |
@@ -163,20 +161,25 @@ func benchmarkQuickSuite(t *testing.B, name string, fns ...func(t *testing.B)) {
 	testReinit()
 	testReinit()
 	benchReinit()
 	benchReinit()
 
 
-	t.Run(name+"-bd"+strconv.Itoa(benchDepth)+"........", f)
+	t.Run(name+"-bd"+strconv.Itoa(benchDepth)+"........", benchmarkOneFn(fns))
+	benchmarkGroupReset()
+}
+
+func benchmarkQuickSuite(t *testing.B, name string, fns ...func(t *testing.B)) {
+	benchmarkVeryQuickSuite(t, name, fns...)
 
 
 	// encoded size of TestStruc is between 20K and 30K for bd=1 // consider buffer=1024 * 16 * benchDepth
 	// encoded size of TestStruc is between 20K and 30K for bd=1 // consider buffer=1024 * 16 * benchDepth
 	testUseIoEncDec = 1024 // (value of defEncByteBufSize): use smaller buffer, and more flushes - it's ok.
 	testUseIoEncDec = 1024 // (value of defEncByteBufSize): use smaller buffer, and more flushes - it's ok.
 	// benchDepth = depth
 	// benchDepth = depth
 	testReinit()
 	testReinit()
 	benchReinit()
 	benchReinit()
-	t.Run(name+"-bd"+strconv.Itoa(benchDepth)+"-buf"+strconv.Itoa(testUseIoEncDec), f)
+	t.Run(name+"-bd"+strconv.Itoa(benchDepth)+"-buf"+strconv.Itoa(testUseIoEncDec), benchmarkOneFn(fns))
 
 
 	testUseIoEncDec = 0
 	testUseIoEncDec = 0
 	// benchDepth = depth
 	// benchDepth = depth
 	testReinit()
 	testReinit()
 	benchReinit()
 	benchReinit()
-	t.Run(name+"-bd"+strconv.Itoa(benchDepth)+"-io.....", f)
+	t.Run(name+"-bd"+strconv.Itoa(benchDepth)+"-io.....", benchmarkOneFn(fns))
 
 
 	benchmarkGroupReset()
 	benchmarkGroupReset()
 }
 }

+ 7 - 2
codec/bench/z_all_x_bench_test.go

@@ -100,9 +100,14 @@ func benchmarkAllJsonDecodeGroup(t *testing.B) {
 	t.Run("Benchmark__JsonIter___Decode", Benchmark__JsonIter___Decode)
 	t.Run("Benchmark__JsonIter___Decode", Benchmark__JsonIter___Decode)
 }
 }
 
 
+func BenchmarkCodecVeryQuickAllJsonSuite(t *testing.B) {
+	benchmarkVeryQuickSuite(t, "json-all", benchmarkAllJsonEncodeGroup, benchmarkAllJsonDecodeGroup)
+}
+
 func BenchmarkCodecQuickAllJsonSuite(t *testing.B) {
 func BenchmarkCodecQuickAllJsonSuite(t *testing.B) {
-	benchmarkQuickSuite(t, "json-all", benchmarkAllJsonEncodeGroup)
-	benchmarkQuickSuite(t, "json-all", benchmarkAllJsonDecodeGroup)
+	benchmarkQuickSuite(t, "json-all", benchmarkAllJsonEncodeGroup, benchmarkAllJsonDecodeGroup)
+	// benchmarkQuickSuite(t, "json-all", benchmarkAllJsonEncodeGroup)
+	// benchmarkQuickSuite(t, "json-all", benchmarkAllJsonDecodeGroup)
 
 
 	// depths := [...]int{1, 4}
 	// depths := [...]int{1, 4}
 	// for _, d := range depths {
 	// for _, d := range depths {