Merge branch 'bench' into largeNbDicts

This commit is contained in:
Yann Collet 2018-08-27 12:12:51 -07:00
commit d97e92dfad
4 changed files with 43 additions and 40 deletions

View File

@ -278,17 +278,25 @@ static size_t local_defaultDecompress(
int BMK_isSuccessful_runOutcome(BMK_runOutcome_t outcome) int BMK_isSuccessful_runOutcome(BMK_runOutcome_t outcome)
{ {
return outcome.tag < 2; return outcome.tag == 0;
} }
/* warning : this function will stop program execution if outcome is invalid ! /* warning : this function will stop program execution if outcome is invalid !
* check outcome validity first, using BMK_isValid_runResult() */ * check outcome validity first, using BMK_isValid_runResult() */
BMK_runTime_t BMK_extract_runTime(BMK_runOutcome_t outcome) BMK_runTime_t BMK_extract_runTime(BMK_runOutcome_t outcome)
{ {
assert(outcome.tag < 2); assert(outcome.tag == 0);
return outcome.internal_never_use_directly; return outcome.internal_never_use_directly;
} }
static BMK_runOutcome_t BMK_runOutcome_error(void)
{
BMK_runOutcome_t b;
memset(&b, 0, sizeof(b));
b.tag = 1;
return b;
}
static BMK_runOutcome_t BMK_setValid_runTime(BMK_runTime_t runTime) static BMK_runOutcome_t BMK_setValid_runTime(BMK_runTime_t runTime)
{ {
BMK_runOutcome_t outcome; BMK_runOutcome_t outcome;
@ -382,6 +390,7 @@ BMK_timedFnState_t* BMK_createTimedFnState(unsigned nbSeconds) {
void BMK_resetTimedFnState(BMK_timedFnState_t* r, unsigned nbSeconds) { void BMK_resetTimedFnState(BMK_timedFnState_t* r, unsigned nbSeconds) {
r->timeSpent_ns = 0; r->timeSpent_ns = 0;
r->timeBudget_ns = (U64)nbSeconds * TIMELOOP_NANOSEC; r->timeBudget_ns = (U64)nbSeconds * TIMELOOP_NANOSEC;
if (!nbSeconds) r->timeBudget_ns = 1;
r->fastestRun.nanoSecPerRun = (U64)(-1LL); r->fastestRun.nanoSecPerRun = (U64)(-1LL);
r->fastestRun.sumOfReturn = (size_t)(-1LL); r->fastestRun.sumOfReturn = (size_t)(-1LL);
r->nbLoops = 1; r->nbLoops = 1;
@ -395,15 +404,15 @@ void BMK_freeTimedFnState(BMK_timedFnState_t* state) {
/* Tells if nb of seconds set in timedFnState for all runs is spent. /* Tells if nb of seconds set in timedFnState for all runs is spent.
* note : this function will return 1 if BMK_benchFunctionTimed() has actually errored. */ * note : this function will return 1 if BMK_benchFunctionTimed() has actually errored. */
int BMK_isCompleted_runOutcome(BMK_runOutcome_t outcome) int BMK_isCompleted_TimedFn(const BMK_timedFnState_t* timedFnState)
{ {
return (outcome.tag >= 1); return (timedFnState->timeSpent_ns >= timedFnState->timeBudget_ns);
} }
#define MINUSABLETIME (TIMELOOP_NANOSEC / 2) /* 0.5 seconds */ #define MINUSABLETIME (TIMELOOP_NANOSEC / 2) /* 0.5 seconds */
BMK_runOutcome_t BMK_benchFunctionTimed( BMK_runOutcome_t BMK_benchTimedFn(
BMK_timedFnState_t* cont, BMK_timedFnState_t* cont,
BMK_benchFn_t benchFn, void* benchPayload, BMK_benchFn_t benchFn, void* benchPayload,
BMK_initFn_t initFn, void* initPayload, BMK_initFn_t initFn, void* initPayload,
@ -413,11 +422,8 @@ BMK_runOutcome_t BMK_benchFunctionTimed(
size_t* blockResults) size_t* blockResults)
{ {
int completed = 0; int completed = 0;
BMK_runOutcome_t r;
BMK_runTime_t bestRunTime = cont->fastestRun; BMK_runTime_t bestRunTime = cont->fastestRun;
r.tag = 2; /* error by default */
while (!completed) { while (!completed) {
BMK_runOutcome_t runResult; BMK_runOutcome_t runResult;
@ -438,8 +444,7 @@ BMK_runOutcome_t BMK_benchFunctionTimed(
cont->nbLoops); cont->nbLoops);
if(!BMK_isSuccessful_runOutcome(runResult)) { /* error : move out */ if(!BMK_isSuccessful_runOutcome(runResult)) { /* error : move out */
r.tag = 2; return BMK_runOutcome_error();
return r;
} }
{ BMK_runTime_t const newRunTime = BMK_extract_runTime(runResult); { BMK_runTime_t const newRunTime = BMK_extract_runTime(runResult);
@ -471,9 +476,7 @@ BMK_runOutcome_t BMK_benchFunctionTimed(
} }
} /* while (!completed) */ } /* while (!completed) */
r.tag = (cont->timeSpent_ns >= cont->timeBudget_ns); /* report if time budget is spent */ return BMK_setValid_runTime(bestRunTime);
r.internal_never_use_directly = bestRunTime;
return r;
} }
@ -624,13 +627,13 @@ static BMK_benchOutcome_t BMK_benchMemAdvancedNoAlloc(
if (!compressionCompleted) { if (!compressionCompleted) {
BMK_runOutcome_t const cOutcome = BMK_runOutcome_t const cOutcome =
BMK_benchFunctionTimed( timeStateCompress, BMK_benchTimedFn( timeStateCompress,
&local_defaultCompress, cctx, &local_defaultCompress, cctx,
&local_initCCtx, &cctxprep, &local_initCCtx, &cctxprep,
nbBlocks, nbBlocks,
srcPtrs, srcSizes, srcPtrs, srcSizes,
cPtrs, cCapacities, cPtrs, cCapacities,
cSizes); cSizes);
if (!BMK_isSuccessful_runOutcome(cOutcome)) { if (!BMK_isSuccessful_runOutcome(cOutcome)) {
return BMK_benchOutcome_error(); return BMK_benchOutcome_error();
@ -654,18 +657,18 @@ static BMK_benchOutcome_t BMK_benchMemAdvancedNoAlloc(
ratioAccuracy, ratio, ratioAccuracy, ratio,
benchResult.cSpeed < (10 MB) ? 2 : 1, (double)benchResult.cSpeed / MB_UNIT); benchResult.cSpeed < (10 MB) ? 2 : 1, (double)benchResult.cSpeed / MB_UNIT);
} }
compressionCompleted = BMK_isCompleted_runOutcome(cOutcome); compressionCompleted = BMK_isCompleted_TimedFn(timeStateCompress);
} }
if(!decompressionCompleted) { if(!decompressionCompleted) {
BMK_runOutcome_t const dOutcome = BMK_runOutcome_t const dOutcome =
BMK_benchFunctionTimed(timeStateDecompress, BMK_benchTimedFn(timeStateDecompress,
&local_defaultDecompress, dctx, &local_defaultDecompress, dctx,
&local_initDCtx, &dctxprep, &local_initDCtx, &dctxprep,
nbBlocks, nbBlocks,
(const void *const *)cPtrs, cSizes, (const void *const *)cPtrs, cSizes,
resPtrs, resSizes, resPtrs, resSizes,
NULL); NULL);
if(!BMK_isSuccessful_runOutcome(dOutcome)) { if(!BMK_isSuccessful_runOutcome(dOutcome)) {
return BMK_benchOutcome_error(); return BMK_benchOutcome_error();
@ -686,7 +689,7 @@ static BMK_benchOutcome_t BMK_benchMemAdvancedNoAlloc(
benchResult.cSpeed < (10 MB) ? 2 : 1, (double)benchResult.cSpeed / MB_UNIT, benchResult.cSpeed < (10 MB) ? 2 : 1, (double)benchResult.cSpeed / MB_UNIT,
(double)benchResult.dSpeed / MB_UNIT); (double)benchResult.dSpeed / MB_UNIT);
} }
decompressionCompleted = BMK_isCompleted_runOutcome(dOutcome); decompressionCompleted = BMK_isCompleted_TimedFn(timeStateDecompress);
} }
} /* while (!(compressionCompleted && decompressionCompleted)) */ } /* while (!(compressionCompleted && decompressionCompleted)) */

View File

@ -265,16 +265,16 @@ void BMK_resetTimedFnState(BMK_timedFnState_t* timedFnState, unsigned nbSeconds)
void BMK_freeTimedFnState(BMK_timedFnState_t* state); void BMK_freeTimedFnState(BMK_timedFnState_t* state);
/* BMK_benchFunctionTimed() : /* BMK_benchTimedFn() :
* Similar to BMK_benchFunction(), * Similar to BMK_benchFunction(),
* tries to find automatically `nbLoops`, so that each run lasts approximately 1 second. * tries to find automatically `nbLoops`, so that each run lasts approximately 1 second.
* Note : minimum `nbLoops` is 1, a run may last more than 1 second if benchFn is slow. * Note : minimum `nbLoops` is 1, a run may last more than 1 second if benchFn is slow.
* Most arguments are the same as BMK_benchFunction() * Most arguments are the same as BMK_benchFunction()
* Usage - initialize a timedFnState, selecting a total nbSeconds allocated for _all_ benchmarks run * Usage - initialize a timedFnState, selecting a total nbSeconds allocated for _all_ benchmarks run
* call BMK_benchFunctionTimed() repetitively, collecting intermediate results (each run is supposed to last about 1 seconds) * call BMK_benchTimedFn() repetitively, collecting intermediate results (each run is supposed to last about 1 seconds)
* Check if time budget is spent using BMK_isCompleted_runOutcome() * Check if time budget is spent using BMK_isCompleted_TimedFn()
*/ */
BMK_runOutcome_t BMK_benchFunctionTimed( BMK_runOutcome_t BMK_benchTimedFn(
BMK_timedFnState_t* timedFnState, BMK_timedFnState_t* timedFnState,
BMK_benchFn_t benchFn, void* benchPayload, BMK_benchFn_t benchFn, void* benchPayload,
BMK_initFn_t initFn, void* initPayload, BMK_initFn_t initFn, void* initPayload,
@ -286,7 +286,7 @@ BMK_runOutcome_t BMK_benchFunctionTimed(
/* Tells if total nb of benchmark runs has exceeded amount of time set in timedFnState /* Tells if total nb of benchmark runs has exceeded amount of time set in timedFnState
*/ */
int BMK_isCompleted_runOutcome(BMK_runOutcome_t outcome); int BMK_isCompleted_TimedFn(const BMK_timedFnState_t* timedFnState);

View File

@ -521,7 +521,7 @@ static size_t benchMem(U32 benchNb,
for (;;) { for (;;) {
void* const dstBuffv = dstBuff; void* const dstBuffv = dstBuff;
BMK_runOutcome_t const bOutcome = BMK_runOutcome_t const bOutcome =
BMK_benchFunctionTimed( tfs, BMK_benchTimedFn( tfs,
benchFunction, buff2, benchFunction, buff2,
NULL, NULL, /* initFn */ NULL, NULL, /* initFn */
1, /* blockCount */ 1, /* blockCount */
@ -544,7 +544,7 @@ static size_t benchMem(U32 benchNb,
(unsigned)newResult.sumOfReturn ); (unsigned)newResult.sumOfReturn );
} }
if ( BMK_isCompleted_runOutcome(bOutcome) ) break; if ( BMK_isCompleted_TimedFn(tfs) ) break;
} }
BMK_freeTimedFnState(tfs); BMK_freeTimedFnState(tfs);
} }

View File

@ -1441,7 +1441,7 @@ BMK_benchMemInvertible( buffers_t buf, contexts_t ctx,
dctxprep.dictBufferSize = dictBufferSize; dctxprep.dictBufferSize = dictBufferSize;
while(!compressionCompleted) { while(!compressionCompleted) {
BMK_runOutcome_t const cOutcome = BMK_benchFunctionTimed(timeStateCompress, BMK_runOutcome_t const cOutcome = BMK_benchTimedFn(timeStateCompress,
&local_defaultCompress, cctx, &local_defaultCompress, cctx,
&local_initCCtx, &cctxprep, &local_initCCtx, &cctxprep,
nbBlocks, nbBlocks,
@ -1461,11 +1461,11 @@ BMK_benchMemInvertible( buffers_t buf, contexts_t ctx,
bResult.cSpeed = (srcSize * TIMELOOP_NANOSEC) / rResult.nanoSecPerRun; bResult.cSpeed = (srcSize * TIMELOOP_NANOSEC) / rResult.nanoSecPerRun;
bResult.cSize = rResult.sumOfReturn; bResult.cSize = rResult.sumOfReturn;
} }
compressionCompleted = BMK_isCompleted_runOutcome(cOutcome); compressionCompleted = BMK_isCompleted_TimedFn(timeStateCompress);
} }
while (!decompressionCompleted) { while (!decompressionCompleted) {
BMK_runOutcome_t const dOutcome = BMK_benchFunctionTimed(timeStateDecompress, BMK_runOutcome_t const dOutcome = BMK_benchTimedFn(timeStateDecompress,
&local_defaultDecompress, dctx, &local_defaultDecompress, dctx,
&local_initDCtx, &dctxprep, &local_initDCtx, &dctxprep,
nbBlocks, nbBlocks,
@ -1484,7 +1484,7 @@ BMK_benchMemInvertible( buffers_t buf, contexts_t ctx,
{ BMK_runTime_t const rResult = BMK_extract_runTime(dOutcome); { BMK_runTime_t const rResult = BMK_extract_runTime(dOutcome);
bResult.dSpeed = (srcSize * TIMELOOP_NANOSEC) / rResult.nanoSecPerRun; bResult.dSpeed = (srcSize * TIMELOOP_NANOSEC) / rResult.nanoSecPerRun;
} }
decompressionCompleted = BMK_isCompleted_runOutcome(dOutcome); decompressionCompleted = BMK_isCompleted_TimedFn(timeStateDecompress);
} }
BMK_freeTimedFnState(timeStateCompress); BMK_freeTimedFnState(timeStateCompress);