bench: reduce nb of return type

runOutcome is enough
removed timedFnOutcome
This commit is contained in:
Yann Collet 2018-08-24 17:28:38 -07:00
parent 6ce7b08f17
commit 2279f3d127
4 changed files with 43 additions and 65 deletions

View File

@ -278,14 +278,14 @@ static size_t local_defaultDecompress(
int BMK_isSuccessful_runOutcome(BMK_runOutcome_t outcome)
{
return outcome.tag == 0;
return outcome.tag < 2;
}
/* warning : this function will stop program execution if outcome is invalid !
* check outcome validity first, using BMK_isValid_runResult() */
BMK_runTime_t BMK_extract_runTime(BMK_runOutcome_t outcome)
{
assert(outcome.tag == 0);
assert(outcome.tag < 2);
return outcome.internal_never_use_directly;
}
@ -317,7 +317,7 @@ BMK_runOutcome_t BMK_benchFunction(
size_t dstSize = 0;
if(!nbLoops) {
RETURN_QUIET_ERROR(1, BMK_runOutcome_t, "nbLoops must be nonzero ");
RETURN_QUIET_ERROR(2, BMK_runOutcome_t, "nbLoops must be nonzero ");
}
/* init */
@ -393,24 +393,9 @@ void BMK_freeTimedFnState(BMK_timedFnState_t* state) {
}
/* check first if the return structure represents an error or a valid result */
int BMK_isSuccessful_timedFnOutcome(BMK_timedFnOutcome_t outcome)
{
return (outcome.tag < 2);
}
/* extract intermediate results from variant type.
* note : this function will abort() program execution if result is not valid.
* check result validity first, by using BMK_isSuccessful_timedFnOutcome() */
BMK_runTime_t BMK_extract_timedFnResult(BMK_timedFnOutcome_t outcome)
{
assert(outcome.tag < 2);
return outcome.internal_never_use_directly;
}
/* 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. */
int BMK_isCompleted_timedFnOutcome(BMK_timedFnOutcome_t outcome)
int BMK_isCompleted_runOutcome(BMK_runOutcome_t outcome)
{
return (outcome.tag >= 1);
}
@ -418,7 +403,7 @@ int BMK_isCompleted_timedFnOutcome(BMK_timedFnOutcome_t outcome)
#define MINUSABLETIME (TIMELOOP_NANOSEC / 2) /* 0.5 seconds */
BMK_timedFnOutcome_t BMK_benchFunctionTimed(
BMK_runOutcome_t BMK_benchFunctionTimed(
BMK_timedFnState_t* cont,
BMK_benchFn_t benchFn, void* benchPayload,
BMK_initFn_t initFn, void* initPayload,
@ -428,7 +413,7 @@ BMK_timedFnOutcome_t BMK_benchFunctionTimed(
size_t* blockResults)
{
int completed = 0;
BMK_timedFnOutcome_t r;
BMK_runOutcome_t r;
BMK_runTime_t bestRunTime = cont->fastestRun;
r.tag = 2; /* error by default */
@ -638,7 +623,7 @@ static BMK_benchOutcome_t BMK_benchMemAdvancedNoAlloc(
while (!(compressionCompleted && decompressionCompleted)) {
if (!compressionCompleted) {
BMK_timedFnOutcome_t const cOutcome =
BMK_runOutcome_t const cOutcome =
BMK_benchFunctionTimed( timeStateCompress,
&local_defaultCompress, cctx,
&local_initCCtx, &cctxprep,
@ -647,11 +632,11 @@ static BMK_benchOutcome_t BMK_benchMemAdvancedNoAlloc(
cPtrs, cCapacities,
cSizes);
if (!BMK_isSuccessful_timedFnOutcome(cOutcome)) {
if (!BMK_isSuccessful_runOutcome(cOutcome)) {
return BMK_benchOutcome_error();
}
{ BMK_runTime_t const cResult = BMK_extract_timedFnResult(cOutcome);
{ BMK_runTime_t const cResult = BMK_extract_runTime(cOutcome);
cSize = cResult.sumOfReturn;
ratio = (double)srcSize / cSize;
{ BMK_benchResult_t newResult;
@ -669,11 +654,11 @@ static BMK_benchOutcome_t BMK_benchMemAdvancedNoAlloc(
ratioAccuracy, ratio,
benchResult.cSpeed < (10 MB) ? 2 : 1, (double)benchResult.cSpeed / MB_UNIT);
}
compressionCompleted = BMK_isCompleted_timedFnOutcome(cOutcome);
compressionCompleted = BMK_isCompleted_runOutcome(cOutcome);
}
if(!decompressionCompleted) {
BMK_timedFnOutcome_t const dOutcome =
BMK_runOutcome_t const dOutcome =
BMK_benchFunctionTimed(timeStateDecompress,
&local_defaultDecompress, dctx,
&local_initDCtx, &dctxprep,
@ -682,11 +667,11 @@ static BMK_benchOutcome_t BMK_benchMemAdvancedNoAlloc(
resPtrs, resSizes,
NULL);
if(!BMK_isSuccessful_timedFnOutcome(dOutcome)) {
if(!BMK_isSuccessful_runOutcome(dOutcome)) {
return BMK_benchOutcome_error();
}
{ BMK_runTime_t const dResult = BMK_extract_timedFnResult(dOutcome);
{ BMK_runTime_t const dResult = BMK_extract_runTime(dOutcome);
U64 const newDSpeed = (srcSize * TIMELOOP_NANOSEC / dResult.nanoSecPerRun);
if (newDSpeed > benchResult.dSpeed)
benchResult.dSpeed = newDSpeed;
@ -701,7 +686,7 @@ static BMK_benchOutcome_t BMK_benchMemAdvancedNoAlloc(
benchResult.cSpeed < (10 MB) ? 2 : 1, (double)benchResult.cSpeed / MB_UNIT,
(double)benchResult.dSpeed / MB_UNIT);
}
decompressionCompleted = BMK_isCompleted_timedFnOutcome(dOutcome);
decompressionCompleted = BMK_isCompleted_runOutcome(dOutcome);
}
} /* while (!(compressionCompleted && decompressionCompleted)) */

View File

@ -216,6 +216,7 @@ int BMK_isSuccessful_runOutcome(BMK_runOutcome_t outcome);
BMK_runTime_t BMK_extract_runTime(BMK_runOutcome_t outcome);
typedef size_t (*BMK_benchFn_t)(const void* src, size_t srcSize, void* dst, size_t dstCapacity, void* customPayload);
typedef size_t (*BMK_initFn_t)(void* initPayload);
@ -263,21 +264,6 @@ BMK_timedFnState_t* BMK_createTimedFnState(unsigned nbSeconds);
void BMK_resetTimedFnState(BMK_timedFnState_t* timedFnState, unsigned nbSeconds);
void BMK_freeTimedFnState(BMK_timedFnState_t* state);
/* define timedFnOutcome */
VARIANT_ERROR_RESULT(BMK_runTime_t, BMK_timedFnOutcome_t);
/* check first if the return structure represents an error or a valid result */
int BMK_isSuccessful_timedFnOutcome(BMK_timedFnOutcome_t outcome);
/* extract intermediate results from variant type.
* note : this function will abort() program execution if result is not valid.
* check result validity first, by using BMK_isSuccessful_timedFnOutcome() */
BMK_runTime_t BMK_extract_timedFnResult(BMK_timedFnOutcome_t outcome);
/* 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. */
int BMK_isCompleted_timedFnOutcome(BMK_timedFnOutcome_t outcome);
/* BMK_benchFunctionTimed() :
* Similar to BMK_benchFunction(),
@ -286,16 +272,23 @@ int BMK_isCompleted_timedFnOutcome(BMK_timedFnOutcome_t outcome);
* Most arguments are the same as BMK_benchFunction()
* 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)
* Check if time budget is spent using BMK_isCompleted_timedFnOutcome()
* Check if time budget is spent using BMK_isCompleted_runOutcome()
*/
BMK_timedFnOutcome_t BMK_benchFunctionTimed(
BMK_timedFnState_t* timedFnState,
BMK_benchFn_t benchFn, void* benchPayload,
BMK_initFn_t initFn, void* initPayload,
size_t blockCount,
const void *const * srcBlockBuffers, const size_t* srcBlockSizes,
void *const * dstBlockBuffers, const size_t* dstBlockCapacities,
size_t* blockResults);
BMK_runOutcome_t BMK_benchFunctionTimed(
BMK_timedFnState_t* timedFnState,
BMK_benchFn_t benchFn, void* benchPayload,
BMK_initFn_t initFn, void* initPayload,
size_t blockCount,
const void *const * srcBlockBuffers, const size_t* srcBlockSizes,
void *const * dstBlockBuffers, const size_t* dstBlockCapacities,
size_t* blockResults);
/* Tells if total nb of benchmark runs has exceeded amount of time set in timedFnState
*/
int BMK_isCompleted_runOutcome(BMK_runOutcome_t outcome);
#endif /* BENCH_H_121279284357 */

View File

@ -520,7 +520,7 @@ static size_t benchMem(U32 benchNb,
bestResult.nanoSecPerRun = (unsigned long long)(-1LL);
for (;;) {
void* const dstBuffv = dstBuff;
BMK_timedFnOutcome_t const bOutcome =
BMK_runOutcome_t const bOutcome =
BMK_benchFunctionTimed( tfs,
benchFunction, buff2,
NULL, NULL, /* initFn */
@ -529,13 +529,13 @@ static size_t benchMem(U32 benchNb,
&dstBuffv, &dstBuffSize,
NULL);
if (!BMK_isSuccessful_timedFnOutcome(bOutcome)) {
if (!BMK_isSuccessful_runOutcome(bOutcome)) {
DISPLAY("ERROR benchmarking function ! ! \n");
errorcode = 1;
goto _cleanOut;
}
{ BMK_runTime_t const newResult = BMK_extract_timedFnResult(bOutcome);
{ BMK_runTime_t const newResult = BMK_extract_runTime(bOutcome);
if (newResult.nanoSecPerRun < bestResult.nanoSecPerRun )
bestResult.nanoSecPerRun = newResult.nanoSecPerRun;
DISPLAY("\r%2u#%-29.29s:%8.1f MB/s (%8u) ",
@ -544,7 +544,7 @@ static size_t benchMem(U32 benchNb,
(unsigned)newResult.sumOfReturn );
}
if ( BMK_isCompleted_timedFnOutcome(bOutcome) ) break;
if ( BMK_isCompleted_runOutcome(bOutcome) ) break;
} }
DISPLAY("\n");

View File

@ -1441,7 +1441,7 @@ BMK_benchMemInvertible( buffers_t buf, contexts_t ctx,
dctxprep.dictBufferSize = dictBufferSize;
while(!compressionCompleted) {
BMK_timedFnOutcome_t const cOutcome = BMK_benchFunctionTimed(timeStateCompress,
BMK_runOutcome_t const cOutcome = BMK_benchFunctionTimed(timeStateCompress,
&local_defaultCompress, cctx,
&local_initCCtx, &cctxprep,
nbBlocks,
@ -1449,22 +1449,22 @@ BMK_benchMemInvertible( buffers_t buf, contexts_t ctx,
dstPtrs, dstCapacities,
dstSizes);
if (!BMK_isSuccessful_timedFnOutcome(cOutcome)) {
if (!BMK_isSuccessful_runOutcome(cOutcome)) {
BMK_benchOutcome_t bOut;
bOut.tag = 1; /* should rather be a function or a constant */
BMK_freeTimedFnState(timeStateCompress);
BMK_freeTimedFnState(timeStateDecompress);
return bOut;
}
{ BMK_runTime_t const rResult = BMK_extract_timedFnResult(cOutcome);
{ BMK_runTime_t const rResult = BMK_extract_runTime(cOutcome);
bResult.cSpeed = (srcSize * TIMELOOP_NANOSEC) / rResult.nanoSecPerRun;
bResult.cSize = rResult.sumOfReturn;
}
compressionCompleted = BMK_isCompleted_timedFnOutcome(cOutcome);
compressionCompleted = BMK_isCompleted_runOutcome(cOutcome);
}
while (!decompressionCompleted) {
BMK_timedFnOutcome_t const dOutcome = BMK_benchFunctionTimed(timeStateDecompress,
BMK_runOutcome_t const dOutcome = BMK_benchFunctionTimed(timeStateDecompress,
&local_defaultDecompress, dctx,
&local_initDCtx, &dctxprep,
nbBlocks,
@ -1472,17 +1472,17 @@ BMK_benchMemInvertible( buffers_t buf, contexts_t ctx,
resPtrs, resSizes,
NULL);
if (!BMK_isSuccessful_timedFnOutcome(dOutcome)) {
if (!BMK_isSuccessful_runOutcome(dOutcome)) {
BMK_benchOutcome_t bOut;
bOut.tag = 1; /* should rather be a function or a constant */
BMK_freeTimedFnState(timeStateCompress);
BMK_freeTimedFnState(timeStateDecompress);
return bOut;
}
{ BMK_runTime_t const rResult = BMK_extract_timedFnResult(dOutcome);
{ BMK_runTime_t const rResult = BMK_extract_runTime(dOutcome);
bResult.dSpeed = (srcSize * TIMELOOP_NANOSEC) / rResult.nanoSecPerRun;
}
decompressionCompleted = BMK_isCompleted_timedFnOutcome(dOutcome);
decompressionCompleted = BMK_isCompleted_runOutcome(dOutcome);
}
BMK_freeTimedFnState(timeStateCompress);