From efbc3e823d21d23cfd942fabdc65cbb10c5a6571 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Thu, 4 Oct 2018 14:27:13 -0700 Subject: [PATCH] fixed paramgrill wrong assert() conditions 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 | 2 +- tests/paramgrill.c | 42 ++++++++++++++++++++---------------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/programs/bench.h b/programs/bench.h index 59f41589..13ca5b50 100644 --- a/programs/bench.h +++ b/programs/bench.h @@ -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); diff --git a/tests/paramgrill.c b/tests/paramgrill.c index 466a156d..7a4be854 100644 --- a/tests/paramgrill.c +++ b/tests/paramgrill.c @@ -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);