]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Reorder Arguments
authorGeorge Lu <gclu@fb.com>
Mon, 18 Jun 2018 19:08:51 +0000 (12:08 -0700)
committerGeorge Lu <gclu@fb.com>
Mon, 18 Jun 2018 20:21:42 +0000 (13:21 -0700)
make initFn nullable

programs/bench.c
programs/bench.h
tests/fullbench.c

index 6d0e1c1ffd39e90e1af6b49825d37407bfc18208..fae4ea0faee21ab613d03fda0e18b7a0f915bd8f 100644 (file)
@@ -281,11 +281,11 @@ static size_t local_defaultDecompress(
 /* benchFn should return error value or out Size */
 /* takes # of blocks and list of size & stuff for each. */
 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 srcBlockBuffers, const size_t* srcBlockSizes,
     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) {
     size_t srcSize = 0, dstSize = 0, ind = 0;
     unsigned toAdd = 1;
@@ -336,7 +336,7 @@ BMK_customReturn_t BMK_benchFunction(
                 }
 
                 clockStart = UTIL_getTime();
-                (*initFn)(initPayload);
+                if(initFn != NULL) { (*initFn)(initPayload); }
 
                 for(i = 0; i < nbLoops; i++) {
                     for(j = 0; j < blockCount; j++) {
@@ -368,6 +368,7 @@ BMK_customReturn_t BMK_benchFunction(
         {        
             unsigned i, j;
             clockStart = UTIL_getTime();
+            if(initFn != NULL) { (*initFn)(initPayload); }
             for(i = 0; i < iter; i++) {
                 for(j = 0; j < blockCount; j++) {
                     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;
             /* Compression */
             DISPLAYLEVEL(2, "%2s-%-17.17s :%10u ->\r", marks[markNb], displayName, (U32)srcSize);
-            compressionResults = BMK_benchFunction(nbBlocks, 
-                srcPtrs, srcSizes, cPtrs, cSizes, 
-                &local_initCCtx, (void*)&cctxprep,
+            compressionResults = BMK_benchFunction(
                 &local_defaultCompress, (void*)(ctx),
+                &local_initCCtx, (void*)&cctxprep,
+                nbBlocks, 
+                srcPtrs, srcSizes, cPtrs, cSizes, 
                 adv->loopMode, adv->nbSeconds);
 
             if(compressionResults.error) {
@@ -544,10 +546,11 @@ BMK_return_t BMK_benchMemAdvanced(const void* srcBuffer, size_t srcSize,
             dctxprep.dctx = dctx;
             dctxprep.dictBuffer = dictBuffer;
             dctxprep.dictBufferSize = dictBufferSize;
-            decompressionResults = BMK_benchFunction(nbBlocks, 
-                (const void * const *)cPtrs, cSizes, resPtrs, resSizes, 
-                &local_initDCtx, (void*)&dctxprep, 
+            decompressionResults = BMK_benchFunction(
                 &local_defaultDecompress, (void*)(dctx),
+                &local_initDCtx, (void*)&dctxprep, 
+                nbBlocks, 
+                (const void * const *)cPtrs, cSizes, resPtrs, resSizes, 
                 adv->loopMode, adv->nbSeconds);
 
             if(decompressionResults.error) {
index 3521668819b41a00a9d844c1e3572446853db006..2030f0a2f105d543ce9435c301dc1138909d03e1 100644 (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 */
 
-/* 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
  * srcSizes - an array of the sizes of above buffers
  * dstBuffers - an array of buffers to be written into by benchFn
  * 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
  * iter - see mode
  * 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 
  *          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,
                         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);
 
 #endif   /* BENCH_H_121279284357 */
index b83eb1c77ebe0d359655e3a1746b647d80be2a53..91a1370dff1d3dd29c0b0076670f0a8f142ea259 100644 (file)
@@ -94,10 +94,6 @@ static size_t BMK_findMaxMem(U64 requiredMem)
 /*_*******************************************************
 *  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)
 {
@@ -431,10 +427,12 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb)
 
     /* 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, 
-            &local_nothing, NULL, 
-            benchFunction, buff2, BMK_timeMode, 1);
+            BMK_timeMode, 1);
         if(r.error) {
             DISPLAY("ERROR %d ! ! \n", r.error);
             exit(1);