MCPcopy Create free account
hub / github.com/F-Stack/f-stack / BMK_benchTimedFn

Function BMK_benchTimedFn

freebsd/contrib/zstd/programs/benchfn.c:211–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209#define MINUSABLETIME (TIMELOOP_NANOSEC / 2) /* 0.5 seconds */
210
211BMK_runOutcome_t BMK_benchTimedFn(BMK_timedFnState_t* cont,
212 BMK_benchParams_t p)
213{
214 PTime const runBudget_ns = cont->runBudget_ns;
215 PTime const runTimeMin_ns = runBudget_ns / 2;
216 int completed = 0;
217 BMK_runTime_t bestRunTime = cont->fastestRun;
218
219 while (!completed) {
220 BMK_runOutcome_t const runResult = BMK_benchFunction(p, cont->nbLoops);
221
222 if(!BMK_isSuccessful_runOutcome(runResult)) { /* error : move out */
223 return runResult;
224 }
225
226 { BMK_runTime_t const newRunTime = BMK_extract_runTime(runResult);
227 double const loopDuration_ns = newRunTime.nanoSecPerRun * cont->nbLoops;
228
229 cont->timeSpent_ns += (unsigned long long)loopDuration_ns;
230
231 /* estimate nbLoops for next run to last approximately 1 second */
232 if (loopDuration_ns > (runBudget_ns / 50)) {
233 double const fastestRun_ns = MIN(bestRunTime.nanoSecPerRun, newRunTime.nanoSecPerRun);
234 cont->nbLoops = (unsigned)(runBudget_ns / fastestRun_ns) + 1;
235 } else {
236 /* previous run was too short : blindly increase workload by x multiplier */
237 const unsigned multiplier = 10;
238 assert(cont->nbLoops < ((unsigned)-1) / multiplier); /* avoid overflow */
239 cont->nbLoops *= multiplier;
240 }
241
242 if(loopDuration_ns < runTimeMin_ns) {
243 /* don't report results for which benchmark run time was too small : increased risks of rounding errors */
244 assert(completed == 0);
245 continue;
246 } else {
247 if(newRunTime.nanoSecPerRun < bestRunTime.nanoSecPerRun) {
248 bestRunTime = newRunTime;
249 }
250 completed = 1;
251 }
252 }
253 } /* while (!completed) */
254
255 return BMK_setValid_runTime(bestRunTime);
256}

Callers 1

Calls 4

BMK_benchFunctionFunction · 0.85
BMK_extract_runTimeFunction · 0.85
BMK_setValid_runTimeFunction · 0.85

Tested by

no test coverage detected