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 !
* check outcome validity first, using BMK_isValid_runResult() */
BMK_runTime_t BMK_extract_runTime(BMK_runOutcome_t outcome)
{
- assert(outcome.tag < 2);
+ assert(outcome.tag == 0);
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)
{
BMK_runOutcome_t outcome;
void BMK_resetTimedFnState(BMK_timedFnState_t* r, unsigned nbSeconds) {
r->timeSpent_ns = 0;
r->timeBudget_ns = (U64)nbSeconds * TIMELOOP_NANOSEC;
+ if (!nbSeconds) r->timeBudget_ns = 1;
r->fastestRun.nanoSecPerRun = (U64)(-1LL);
r->fastestRun.sumOfReturn = (size_t)(-1LL);
r->nbLoops = 1;
/* 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_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 */
-BMK_runOutcome_t BMK_benchFunctionTimed(
+BMK_runOutcome_t BMK_benchTimedFn(
BMK_timedFnState_t* cont,
BMK_benchFn_t benchFn, void* benchPayload,
BMK_initFn_t initFn, void* initPayload,
size_t* blockResults)
{
int completed = 0;
- BMK_runOutcome_t r;
BMK_runTime_t bestRunTime = cont->fastestRun;
- r.tag = 2; /* error by default */
-
while (!completed) {
BMK_runOutcome_t runResult;
cont->nbLoops);
if(!BMK_isSuccessful_runOutcome(runResult)) { /* error : move out */
- r.tag = 2;
- return r;
+ return BMK_runOutcome_error();
}
{ BMK_runTime_t const newRunTime = BMK_extract_runTime(runResult);
}
} /* while (!completed) */
- r.tag = (cont->timeSpent_ns >= cont->timeBudget_ns); /* report if time budget is spent */
- r.internal_never_use_directly = bestRunTime;
- return r;
+ return BMK_setValid_runTime(bestRunTime);
}
if (!compressionCompleted) {
BMK_runOutcome_t const cOutcome =
- BMK_benchFunctionTimed( timeStateCompress,
- &local_defaultCompress, cctx,
- &local_initCCtx, &cctxprep,
- nbBlocks,
- srcPtrs, srcSizes,
- cPtrs, cCapacities,
- cSizes);
+ BMK_benchTimedFn( timeStateCompress,
+ &local_defaultCompress, cctx,
+ &local_initCCtx, &cctxprep,
+ nbBlocks,
+ srcPtrs, srcSizes,
+ cPtrs, cCapacities,
+ cSizes);
if (!BMK_isSuccessful_runOutcome(cOutcome)) {
return BMK_benchOutcome_error();
ratioAccuracy, ratio,
benchResult.cSpeed < (10 MB) ? 2 : 1, (double)benchResult.cSpeed / MB_UNIT);
}
- compressionCompleted = BMK_isCompleted_runOutcome(cOutcome);
+ compressionCompleted = BMK_isCompleted_TimedFn(timeStateCompress);
}
if(!decompressionCompleted) {
BMK_runOutcome_t const dOutcome =
- BMK_benchFunctionTimed(timeStateDecompress,
- &local_defaultDecompress, dctx,
- &local_initDCtx, &dctxprep,
- nbBlocks,
- (const void *const *)cPtrs, cSizes,
- resPtrs, resSizes,
- NULL);
+ BMK_benchTimedFn(timeStateDecompress,
+ &local_defaultDecompress, dctx,
+ &local_initDCtx, &dctxprep,
+ nbBlocks,
+ (const void *const *)cPtrs, cSizes,
+ resPtrs, resSizes,
+ NULL);
if(!BMK_isSuccessful_runOutcome(dOutcome)) {
return BMK_benchOutcome_error();
benchResult.cSpeed < (10 MB) ? 2 : 1, (double)benchResult.cSpeed / MB_UNIT,
(double)benchResult.dSpeed / MB_UNIT);
}
- decompressionCompleted = BMK_isCompleted_runOutcome(dOutcome);
+ decompressionCompleted = BMK_isCompleted_TimedFn(timeStateDecompress);
}
} /* while (!(compressionCompleted && decompressionCompleted)) */
void BMK_freeTimedFnState(BMK_timedFnState_t* state);
-/* BMK_benchFunctionTimed() :
+/* BMK_benchTimedFn() :
* Similar to BMK_benchFunction(),
* 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.
* 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_runOutcome()
+ * 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_TimedFn()
*/
-BMK_runOutcome_t BMK_benchFunctionTimed(
+BMK_runOutcome_t BMK_benchTimedFn(
BMK_timedFnState_t* timedFnState,
BMK_benchFn_t benchFn, void* benchPayload,
BMK_initFn_t initFn, void* initPayload,
/* 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);
dctxprep.dictBufferSize = dictBufferSize;
while(!compressionCompleted) {
- BMK_runOutcome_t const cOutcome = BMK_benchFunctionTimed(timeStateCompress,
+ BMK_runOutcome_t const cOutcome = BMK_benchTimedFn(timeStateCompress,
&local_defaultCompress, cctx,
&local_initCCtx, &cctxprep,
nbBlocks,
bResult.cSpeed = (srcSize * TIMELOOP_NANOSEC) / rResult.nanoSecPerRun;
bResult.cSize = rResult.sumOfReturn;
}
- compressionCompleted = BMK_isCompleted_runOutcome(cOutcome);
+ compressionCompleted = BMK_isCompleted_TimedFn(timeStateCompress);
}
while (!decompressionCompleted) {
- BMK_runOutcome_t const dOutcome = BMK_benchFunctionTimed(timeStateDecompress,
+ BMK_runOutcome_t const dOutcome = BMK_benchTimedFn(timeStateDecompress,
&local_defaultDecompress, dctx,
&local_initDCtx, &dctxprep,
nbBlocks,
{ BMK_runTime_t const rResult = BMK_extract_runTime(dOutcome);
bResult.dSpeed = (srcSize * TIMELOOP_NANOSEC) / rResult.nanoSecPerRun;
}
- decompressionCompleted = BMK_isCompleted_runOutcome(dOutcome);
+ decompressionCompleted = BMK_isCompleted_TimedFn(timeStateDecompress);
}
BMK_freeTimedFnState(timeStateCompress);