]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed paramgrill wrong assert() conditions 1353/head
authorYann Collet <cyan@fb.com>
Thu, 4 Oct 2018 21:27:13 +0000 (14:27 -0700)
committerYann Collet <cyan@fb.com>
Thu, 4 Oct 2018 21:27:13 +0000 (14:27 -0700)
and slightly refactored affected function.

Honestly, the formula calculating variance should get a second reviewing round,
it's not clear if it's correct.

programs/bench.h
tests/paramgrill.c

index 59f41589625e1ffd50a330127adec9db57483638..13ca5b50b4612881e04005a5d59b44e2680a8c03 100644 (file)
@@ -45,7 +45,7 @@ typedef struct {
     size_t cSize;
     unsigned long long cSpeed;   /* bytes / sec */
     unsigned long long dSpeed;
-    size_t cMem;                 /* ? what is reported ? */
+    size_t cMem;                 /* memory usage during compression */
 } BMK_benchResult_t;
 
 VARIANT_ERROR_RESULT(BMK_benchResult_t, BMK_benchOutcome_t);
index 466a156d375324ba3d3536a8d5a0c1afd449148c..7a4be854a46bfe742ec64556fb7c0950cd2d1400 100644 (file)
@@ -1552,39 +1552,36 @@ static int allBench(BMK_benchResult_t* resultPtr,
                 BMK_benchResult_t* winnerResult, int feas)
 {
     BMK_benchResult_t benchres;
-    U64 loopDurationC = 0, loopDurationD = 0;
     double uncertaintyConstantC = 3., uncertaintyConstantD = 3.;
     double winnerRS;
 
-    /* initial benchmarking, gives exact ratio and memory, warms up future runs */
-    CBENCHMARK(1, benchres, tmp, BMK_both, 2);
+    BMK_benchOutcome_t const outcome = BMK_benchMemInvertible(buf, ctx, BASE_CLEVEL, &cParams, BMK_both, 2);
+    if (!BMK_isSuccessful_benchOutcome(outcome)) {
+        DEBUGOUTPUT("Benchmarking failed \n");
+        return ERROR_RESULT;
+    }
+    benchres = BMK_extract_benchResult(outcome);
 
     winnerRS = resultScore(*winnerResult, buf.srcSize, target);
-    DEBUGOUTPUT("WinnerScore: %f\n ", winnerRS);
+    DEBUGOUTPUT("WinnerScore: %f \n ", winnerRS);
 
     *resultPtr = benchres;
 
-    /* calculate uncertainty in compression / decompression runs */
-    if(benchres.cSpeed) {
-        loopDurationC = (((U64)buf.srcSize * TIMELOOP_NANOSEC) / benchres.cSpeed);
-        uncertaintyConstantC = ((loopDurationC + (double)(2 * g_clockGranularity))/loopDurationC);
-    }
-
-    if(benchres.dSpeed) {
-        loopDurationD = (((U64)buf.srcSize * TIMELOOP_NANOSEC) / benchres.dSpeed);
-        uncertaintyConstantD = ((loopDurationD + (double)(2 * g_clockGranularity))/loopDurationD);
-    }
-
     /* anything with worse ratio in feas is definitely worse, discard */
     if(feas && benchres.cSize < winnerResult->cSize && !g_optmode) {
         return WORSE_RESULT;
     }
 
-    /* ensure all measurements last a minimum time, to reduce measurement errors */
-    assert(loopDurationC >= TIMELOOP_NANOSEC / 10);
-    assert(loopDurationD >= TIMELOOP_NANOSEC / 10);
+    /* calculate uncertainty in compression / decompression runs */
+    if (benchres.cSpeed) {
+        U64 const loopDurationC = (((U64)buf.srcSize * TIMELOOP_NANOSEC) / benchres.cSpeed);
+        uncertaintyConstantC = ((loopDurationC + (double)(2 * g_clockGranularity))/loopDurationC);
+    }
 
-    *resultPtr = benchres;
+    if (benchres.dSpeed) {
+        U64 const loopDurationD = (((U64)buf.srcSize * TIMELOOP_NANOSEC) / benchres.dSpeed);
+        uncertaintyConstantD = ((loopDurationD + (double)(2 * g_clockGranularity))/loopDurationD);
+    }
 
     /* optimistic assumption of benchres */
     {   BMK_benchResult_t resultMax = benchres;
@@ -1599,8 +1596,6 @@ static int allBench(BMK_benchResult_t* resultPtr,
         }
     }
 
-    *resultPtr = benchres;
-
     /* compare by resultScore when in infeas */
     /* compare by compareResultLT when in feas */
     if((!feas && (resultScore(benchres, buf.srcSize, target) > resultScore(*winnerResult, buf.srcSize, target))) ||
@@ -1623,7 +1618,10 @@ static int benchMemo(BMK_benchResult_t* resultPtr,
     static int bmcount = 0;
     int res;
 
-    if(memoTableGet(memoTableArray, cParams) >= INFEASIBLE_THRESHOLD || redundantParams(cParams, target, buf.maxBlockSize)) { return WORSE_RESULT; }
+    if ( memoTableGet(memoTableArray, cParams) >= INFEASIBLE_THRESHOLD
+      || redundantParams(cParams, target, buf.maxBlockSize) ) {
+        return WORSE_RESULT;
+    }
 
     res = allBench(resultPtr, buf, ctx, cParams, target, winnerResult, feas);