Reorder Arguments

make initFn nullable
This commit is contained in:
George Lu
2018-06-18 13:21:42 -07:00
parent 0d1ee22990
commit e482e328cd
3 changed files with 26 additions and 23 deletions
+12 -9
View File
@@ -281,11 +281,11 @@ static size_t local_defaultDecompress(
/* benchFn should return error value or out Size */ /* benchFn should return error value or out Size */
/* takes # of blocks and list of size & stuff for each. */ /* takes # of blocks and list of size & stuff for each. */
BMK_customReturn_t BMK_benchFunction( BMK_customReturn_t BMK_benchFunction(
size_t (*benchFn)(const void*, size_t, void*, size_t, void*), void* benchPayload,
size_t (*initFn)(void*), void* initPayload,
size_t blockCount, size_t blockCount,
const void* const * const srcBlockBuffers, const size_t* srcBlockSizes, const void* const * const srcBlockBuffers, const size_t* srcBlockSizes,
void* const * const dstBlockBuffers, const size_t* dstBlockCapacities, void* const * const dstBlockBuffers, const size_t* dstBlockCapacities,
size_t (*initFn)(void*), void* initPayload,
size_t (*benchFn)(const void*, size_t, void*, size_t, void*), void* benchPayload,
unsigned mode, unsigned iter) { unsigned mode, unsigned iter) {
size_t srcSize = 0, dstSize = 0, ind = 0; size_t srcSize = 0, dstSize = 0, ind = 0;
unsigned toAdd = 1; unsigned toAdd = 1;
@@ -336,7 +336,7 @@ BMK_customReturn_t BMK_benchFunction(
} }
clockStart = UTIL_getTime(); clockStart = UTIL_getTime();
(*initFn)(initPayload); if(initFn != NULL) { (*initFn)(initPayload); }
for(i = 0; i < nbLoops; i++) { for(i = 0; i < nbLoops; i++) {
for(j = 0; j < blockCount; j++) { for(j = 0; j < blockCount; j++) {
@@ -368,6 +368,7 @@ BMK_customReturn_t BMK_benchFunction(
{ {
unsigned i, j; unsigned i, j;
clockStart = UTIL_getTime(); clockStart = UTIL_getTime();
if(initFn != NULL) { (*initFn)(initPayload); }
for(i = 0; i < iter; i++) { for(i = 0; i < iter; i++) {
for(j = 0; j < blockCount; j++) { for(j = 0; j < blockCount; j++) {
size_t res = (*benchFn)(srcBlockBuffers[j], srcBlockSizes[j], dstBlockBuffers[j], dstBlockCapacities[j], benchPayload); size_t res = (*benchFn)(srcBlockBuffers[j], srcBlockSizes[j], dstBlockBuffers[j], dstBlockCapacities[j], benchPayload);
@@ -511,10 +512,11 @@ BMK_return_t BMK_benchMemAdvanced(const void* srcBuffer, size_t srcSize,
cctxprep.adv = adv; cctxprep.adv = adv;
/* Compression */ /* Compression */
DISPLAYLEVEL(2, "%2s-%-17.17s :%10u ->\r", marks[markNb], displayName, (U32)srcSize); DISPLAYLEVEL(2, "%2s-%-17.17s :%10u ->\r", marks[markNb], displayName, (U32)srcSize);
compressionResults = BMK_benchFunction(nbBlocks, compressionResults = BMK_benchFunction(
srcPtrs, srcSizes, cPtrs, cSizes,
&local_initCCtx, (void*)&cctxprep,
&local_defaultCompress, (void*)(ctx), &local_defaultCompress, (void*)(ctx),
&local_initCCtx, (void*)&cctxprep,
nbBlocks,
srcPtrs, srcSizes, cPtrs, cSizes,
adv->loopMode, adv->nbSeconds); adv->loopMode, adv->nbSeconds);
if(compressionResults.error) { if(compressionResults.error) {
@@ -544,10 +546,11 @@ BMK_return_t BMK_benchMemAdvanced(const void* srcBuffer, size_t srcSize,
dctxprep.dctx = dctx; dctxprep.dctx = dctx;
dctxprep.dictBuffer = dictBuffer; dctxprep.dictBuffer = dictBuffer;
dctxprep.dictBufferSize = dictBufferSize; dctxprep.dictBufferSize = dictBufferSize;
decompressionResults = BMK_benchFunction(nbBlocks, decompressionResults = BMK_benchFunction(
(const void * const *)cPtrs, cSizes, resPtrs, resSizes,
&local_initDCtx, (void*)&dctxprep,
&local_defaultDecompress, (void*)(dctx), &local_defaultDecompress, (void*)(dctx),
&local_initDCtx, (void*)&dctxprep,
nbBlocks,
(const void * const *)cPtrs, cSizes, resPtrs, resSizes,
adv->loopMode, adv->nbSeconds); adv->loopMode, adv->nbSeconds);
if(decompressionResults.error) { if(decompressionResults.error) {
+9 -7
View File
@@ -137,14 +137,15 @@ BMK_return_t BMK_benchMemAdvanced(const void* srcBuffer, size_t srcSize,
/* This function benchmarks the running time two functions (function specifics described */ /* This function benchmarks the running time two functions (function specifics described */
/* blockCount - number of blocks (size of srcBuffers, srcSizes, dstBuffers, dstCapacities) /* benchFn - (*benchFn)(srcBuffers[i], srcSizes[i], dstBuffers[i], dstCapacities[i], benchPayload)
* is run a variable number of times, specified by mode and iter args
* initFn - (*initFn)(initPayload) is run once per benchmark at the beginning. This argument can
* be NULL, in which case nothing is run.
* blockCount - number of blocks (size of srcBuffers, srcSizes, dstBuffers, dstCapacities)
* srcBuffers - an array of buffers to be operated on by benchFn * srcBuffers - an array of buffers to be operated on by benchFn
* srcSizes - an array of the sizes of above buffers * srcSizes - an array of the sizes of above buffers
* dstBuffers - an array of buffers to be written into by benchFn * dstBuffers - an array of buffers to be written into by benchFn
* dstCapacities - an array of the capacities of above buffers. * dstCapacities - an array of the capacities of above buffers.
* initFn - (*initFn)(initPayload) is run once per benchmark
* benchFn - (*benchFn)(srcBuffers[i], srcSizes[i], dstBuffers[i], dstCapacities[i], benchPayload)
* is run a variable number of times, specified by mode and iter args
* mode - if 0, iter will be interpreted as the minimum number of seconds to run * mode - if 0, iter will be interpreted as the minimum number of seconds to run
* iter - see mode * iter - see mode
* return * return
@@ -157,11 +158,12 @@ BMK_return_t BMK_benchMemAdvanced(const void* srcBuffer, size_t srcSize,
* into dstBuffer, hence this value will be the total amount of bytes written to * into dstBuffer, hence this value will be the total amount of bytes written to
* dstBuffer. * dstBuffer.
*/ */
BMK_customReturn_t BMK_benchFunction(size_t blockCount, BMK_customReturn_t BMK_benchFunction(
size_t (*benchFn)(const void*, size_t, void*, size_t, void*), void* benchPayload,
size_t (*initFn)(void*), void* initPayload,
size_t blockCount,
const void* const * const srcBuffers, const size_t* srcSizes, const void* const * const srcBuffers, const size_t* srcSizes,
void* const * const dstBuffers, const size_t* dstCapacities, void* const * const dstBuffers, const size_t* dstCapacities,
size_t (*initFn)(void*), void* initPayload,
size_t (*benchFn)(const void*, size_t, void*, size_t, void*), void* benchPayload,
unsigned mode, unsigned iter); unsigned mode, unsigned iter);
#endif /* BENCH_H_121279284357 */ #endif /* BENCH_H_121279284357 */
+5 -7
View File
@@ -94,10 +94,6 @@ static size_t BMK_findMaxMem(U64 requiredMem)
/*_******************************************************* /*_*******************************************************
* Benchmark wrappers * Benchmark wrappers
*********************************************************/ *********************************************************/
size_t local_nothing(void* x) {
(void)x;
return 0;
}
size_t local_ZSTD_compress(const void* src, size_t srcSize, void* dst, size_t dstSize, void* buff2) size_t local_ZSTD_compress(const void* src, size_t srcSize, void* dst, size_t dstSize, void* buff2)
{ {
@@ -431,10 +427,12 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb)
/* benchmark loop */ /* benchmark loop */
{ {
BMK_customReturn_t r = BMK_benchFunction(1, &src, &srcSize, BMK_customReturn_t r = BMK_benchFunction(
benchFunction, buff2,
NULL, NULL,
1, &src, &srcSize,
(void * const * const)&dstBuff, &dstBuffSize, (void * const * const)&dstBuff, &dstBuffSize,
&local_nothing, NULL, BMK_timeMode, 1);
benchFunction, buff2, BMK_timeMode, 1);
if(r.error) { if(r.error) {
DISPLAY("ERROR %d ! ! \n", r.error); DISPLAY("ERROR %d ! ! \n", r.error);
exit(1); exit(1);