]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Merge remote-tracking branch 'refs/remotes/Cyan4973/dev060' into dev
authorinikep <inikep@gmail.com>
Tue, 22 Mar 2016 13:38:34 +0000 (14:38 +0100)
committerinikep <inikep@gmail.com>
Tue, 22 Mar 2016 13:38:34 +0000 (14:38 +0100)
# Conflicts:
# lib/zstd_compress.c
# programs/bench.c

1  2 
lib/zstd_compress.c
lib/zstd_internal.h
programs/.gitignore
programs/bench.c
programs/bench.h
programs/fullbench.c
programs/zstdcli.c

index 2ee25cc934062798d15c39f1b607926e878bc7e5,cfb2519ad2743cb5a94b75e162aba3cf6309cfc6..266999ca70808518c7761bad011a763ec093dfec
@@@ -266,15 -267,14 +268,15 @@@ size_t ZSTD_copyCCtx(ZSTD_CCtx* dstCCtx
      memcpy(dstCCtx->headerBuffer , srcCCtx->headerBuffer, srcCCtx->hbSize);
  
      /* copy dictionary pointers */
-     dstCCtx->nextToUpdate= srcCCtx->nextToUpdate;
-     dstCCtx->nextToUpdate3 = srcCCtx->nextToUpdate3;
-     dstCCtx->nextSrc     = srcCCtx->nextSrc;
-     dstCCtx->base        = srcCCtx->base;
-     dstCCtx->dictBase    = srcCCtx->dictBase;
-     dstCCtx->dictLimit   = srcCCtx->dictLimit;
-     dstCCtx->lowLimit    = srcCCtx->lowLimit;
-     dstCCtx->loadedDictEnd = srcCCtx->loadedDictEnd;
+     dstCCtx->nextToUpdate = srcCCtx->nextToUpdate;
+     dstCCtx->nextToUpdate3= srcCCtx->nextToUpdate3;
+     dstCCtx->nextSrc      = srcCCtx->nextSrc;
+     dstCCtx->base         = srcCCtx->base;
+     dstCCtx->dictBase     = srcCCtx->dictBase;
+     dstCCtx->dictLimit    = srcCCtx->dictLimit;
+     dstCCtx->lowLimit     = srcCCtx->lowLimit;
+     dstCCtx->loadedDictEnd= srcCCtx->loadedDictEnd;
 +    dstCCtx->additionalParam = srcCCtx->additionalParam;
  
      /* copy entropy tables */
      dstCCtx->flagStaticTables = srcCCtx->flagStaticTables;
Simple merge
Simple merge
index e0db60e5b6bfbdf1d1988968f2bdeddfd02751e5,c74c03df2247f652dbf5d97df17ada831a595a90..5b2e5644a5c0800469e7ded4261f289121dfd5dd
  /* *************************************
  *  Constants
  ***************************************/
- #define NBLOOPS    3
- #define TIMELOOP   2500
 +#ifndef ZSTD_VERSION
 +#  define ZSTD_VERSION ""
 +#endif
 +
+ #define NBLOOPS          3
+ #define TIMELOOP_S       1
+ #define ACTIVEPERIOD_S  70
+ #define COOLPERIOD_S    10
  
  #define KB *(1 <<10)
  #define MB *(1 <<20)
@@@ -128,15 -126,13 +130,15 @@@ static U32 g_displayLevel = 2;   /* 0 
  /* *************************************
  *  Benchmark Parameters
  ***************************************/
- static int nbIterations = NBLOOPS;
+ static U32 g_nbIterations = NBLOOPS;
  static size_t g_blockSize = 0;
  
- void BMK_SetNbIterations(int nbLoops)
 +void BMK_setNotificationLevel(unsigned level) { g_displayLevel=level; }
 +
+ void BMK_SetNbIterations(unsigned nbLoops)
  {
-     nbIterations = nbLoops;
-     DISPLAYLEVEL(2, "- %i iterations -\n", nbIterations);
+     g_nbIterations = nbLoops;
 -    DISPLAY("- %i iterations -\n", g_nbIterations);
++    DISPLAYLEVEL(2, "- %i iterations -\n", g_nbIterations);
  }
  
  void BMK_SetBlockSize(size_t blockSize)
@@@ -245,14 -198,10 +213,11 @@@ static int BMK_benchMem(const void* src
      ZSTD_CCtx* ctx = ZSTD_createCCtx();
      ZSTD_DCtx* refDCtx = ZSTD_createDCtx();
      ZSTD_DCtx* dctx = ZSTD_createDCtx();
-     U64 crcOrig = XXH64(srcBuffer, srcSize, 0);
-     U32 nbBlocks = 0;
-     size_t cSize = 0;
-         
-     /* init */
-     if (strlen(displayName)>17) displayName += strlen(displayName)-17;   /* can only display 17 characters */
 +
-     /* Memory allocation & restrictions */
+     U64 const crcOrig = XXH64(srcBuffer, srcSize, 0);
+     U32 nbBlocks;
+     /* checks */
      if (!compressedBuffer || !resultBuffer || !blockTable || !refCtx || !ctx || !refDCtx || !dctx)
          EXM_THROW(31, "not enough memory");
  
          double fastestC = 100000000., fastestD = 100000000.;
          double ratio = 0.;
          U64 crcCheck = 0;
+         clock_t coolTime = clock();
+         U32 testNb;
  
 -        DISPLAY("\r%79s\r", "");
 +        DISPLAYLEVEL(2, "\r%79s\r", "");
-         for (loopNb = 1; loopNb <= nbIterations; loopNb++) {
+         for (testNb = 1; testNb <= (g_nbIterations + !g_nbIterations); testNb++) {
              int nbLoops;
-             int milliTime;
-             U32 blockNb;
+             clock_t clockStart, clockSpan;
+             clock_t const clockLoop = g_nbIterations ? TIMELOOP_S * CLOCKS_PER_SEC : 10;
+             /* overheat protection */
+             if (BMK_clockSpan(coolTime) > ACTIVEPERIOD_S * CLOCKS_PER_SEC) {
+                 DISPLAY("\rcooling down ...    \r");
+                 BMK_sleep(COOLPERIOD_S);
+                 coolTime = clock();
+             }
  
              /* Compression */
-             DISPLAYLEVEL(2, "%2i-%-17.17s :%10u ->\r", loopNb, displayName, (U32)srcSize);
-             memset(compressedBuffer, 0xE5, maxCompressedSize);
-             nbLoops = 0;
-             milliTime = BMK_GetMilliStart();
-             while (BMK_GetMilliStart() == milliTime);
-             milliTime = BMK_GetMilliStart();
-             while (BMK_GetMilliSpan(milliTime) < TIMELOOP) {
-                 ZSTD_compressBegin_advanced(refCtx, dictBuffer, dictBufferSize, ZSTD_getParams(cLevel, MAX(dictBufferSize, largestBlockSize)));
 -            DISPLAY("%2i-%-17.17s :%10u ->\r", testNb, displayName, (U32)srcSize);
++            DISPLAYLEVEL(2, "%2i-%-17.17s :%10u ->\r", testNb, displayName, (U32)srcSize);
+             memset(compressedBuffer, 0xE5, maxCompressedSize);  /* warm up and erase result buffer */
+             clockStart = clock();
+             while (clock() == clockStart);
+             clockStart = clock();
+             for (nbLoops = 0 ; BMK_clockSpan(clockStart) < clockLoop ; nbLoops++) {
+                 U32 blockNb;
+                 ZSTD_compressBegin_usingDict(refCtx, dictBuffer, dictBufferSize, cLevel);
                  for (blockNb=0; blockNb<nbBlocks; blockNb++) {
-                     size_t rSize = ZSTD_compress_usingPreparedCCtx(ctx, refCtx,
+                     size_t const rSize = ZSTD_compress_usingPreparedCCtx(ctx, refCtx,
                                          blockTable[blockNb].cPtr,  blockTable[blockNb].cRoom,
                                          blockTable[blockNb].srcPtr,blockTable[blockNb].srcSize);
                      if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_compress_usingPreparedCCtx() failed : %s", ZSTD_getErrorName(rSize));
                      blockTable[blockNb].cSize = rSize;
-                 }
-                 nbLoops++;
-             }
-             milliTime = BMK_GetMilliSpan(milliTime);
+             }   }
+             clockSpan = BMK_clockSpan(clockStart);
  
+             if ((double)clockSpan < fastestC*nbLoops) fastestC = (double)clockSpan / nbLoops;
              cSize = 0;
-             for (blockNb=0; blockNb<nbBlocks; blockNb++)
-                 cSize += blockTable[blockNb].cSize;
-             if ((double)milliTime < fastestC*nbLoops) fastestC = (double)milliTime / nbLoops;
+             { U32 blockNb; for (blockNb=0; blockNb<nbBlocks; blockNb++) cSize += blockTable[blockNb].cSize; }
              ratio = (double)srcSize / (double)cSize;
-             DISPLAYLEVEL(2, "%2i-%-17.17s :%10i ->%10i (%5.3f),%6.1f MB/s\r", loopNb, displayName, (int)srcSize, (int)cSize, ratio, (double)srcSize / fastestC / 1000.);
 -            DISPLAY("%2i-%-17.17s :%10u ->%10u (%5.3f),%6.1f MB/s\r",
++            DISPLAYLEVEL(2, "%2i-%-17.17s :%10u ->%10u (%5.3f),%6.1f MB/s\r",
+                     testNb, displayName, (U32)srcSize, (U32)cSize, ratio,
+                     (double)srcSize / 1000000. / (fastestC / CLOCKS_PER_SEC) );
  
  #if 1
              /* Decompression */
                      blockTable[blockNb].resSize = regenSize;
              }   }
  
-             milliTime = BMK_GetMilliSpan(milliTime);
-             if ((double)milliTime < fastestD*nbLoops) fastestD = (double)milliTime / nbLoops;
-             DISPLAYLEVEL(2, "%2i-%-17.17s :%10i ->%10i (%5.3f),%6.1f MB/s ,%6.1f MB/s\r", loopNb, displayName, (int)srcSize, (int)cSize, ratio, (double)srcSize / fastestC / 1000., (double)srcSize / fastestD / 1000.);
+             clockSpan = BMK_clockSpan(clockStart);
+             if ((double)clockSpan < fastestD*nbLoops) fastestD = (double)clockSpan / nbLoops;
 -            DISPLAY("%2i-%-17.17s :%10u ->%10u (%5.3f),%6.1f MB/s ,%6.1f MB/s\r",
++            DISPLAYLEVEL(2, "%2i-%-17.17s :%10u ->%10u (%5.3f),%6.1f MB/s ,%6.1f MB/s\r",
+                     testNb, displayName, (U32)srcSize, (U32)cSize, ratio,
+                     (double)srcSize / 1000000. / (fastestC / CLOCKS_PER_SEC),
+                     (double)srcSize / 1000000. / (fastestD / CLOCKS_PER_SEC) );
  
              /* CRC Checking */
  _findError:
                          printf("no difference detected\n");
                  }   }
                  break;
-             }
+             }   /* if (crcOrig!=crcCheck) */
  #endif
-         }
+         }   /* for (testNb = 1; testNb <= (g_nbIterations + !g_nbIterations); testNb++) */
 -        DISPLAY("%2i#\n", cLevel);
 +
-         if (crcOrig == crcCheck)
-         {
-             DISPLAYLEVEL(2, "%2i-%-17.17s :%10i ->%10i (%5.3f),%6.1f MB/s ,%6.1f MB/s \n", cLevel, displayName, (int)srcSize, (int)cSize, ratio, (double)srcSize / fastestC / 1000., (double)srcSize / fastestD / 1000.);
++        if (crcOrig == crcCheck) {
 +            result->ratio = ratio;
 +            result->cSize = cSize;
-             result->cSpeed = (double)srcSize / fastestC / 1000.; 
-             result->dSpeed = (double)srcSize / fastestD / 1000.;
++            result->cSpeed = (double)srcSize / 1000000. / (fastestC / CLOCKS_PER_SEC); 
++            result->dSpeed = (double)srcSize / 1000000. / (fastestD / CLOCKS_PER_SEC);
 +        }
-         else
-             DISPLAYLEVEL(2, "%2i-\n", cLevel);
-     }
++        DISPLAYLEVEL(2, "%2i#\n", cLevel);
+     }   /* Bench */
  
      /* clean up */
      free(compressedBuffer);
@@@ -425,45 -376,20 +400,45 @@@ static void BMK_benchCLevel(void* srcBu
                              const size_t* fileSizes, unsigned nbFiles,
                              const void* dictBuffer, size_t dictBufferSize)
  {
 -    if (cLevel < 0) {  /* range mode : test all levels from 1 to l */
 -        int l;
 -        for (l=1; l <= -cLevel; l++) {
 -            BMK_benchMem(srcBuffer, benchedSize,
 -                         displayName, l,
 -                         fileSizes, nbFiles,
 -                         dictBuffer, dictBufferSize);
 +    benchResult_t result, total;
 +    int l;
 +
 +    const char* pch = strrchr(displayName, '\\'); /* Windows */
 +    if (!pch) pch = strrchr(displayName, '/'); /* Linux */
 +    if (pch) displayName = pch+1;
 +
 +    memset(&result, 0, sizeof(result));
 +    memset(&total, 0, sizeof(total));
 +
 +    if (g_displayLevel == 1 && !additionalParam)
-         DISPLAY("bench %s: input %u bytes, %i iterations, %u KB blocks\n", ZSTD_VERSION, (U32)benchedSize, nbIterations, (U32)(g_blockSize>>10));
++        DISPLAY("bench %s: input %u bytes, %i iterations, %u KB blocks\n", ZSTD_VERSION, (U32)benchedSize, g_nbIterations, (U32)(g_blockSize>>10));
 +
 +    if (cLevelLast < cLevel) cLevelLast = cLevel;
 +
 +    for (l=cLevel; l <= cLevelLast; l++) {           
 +        BMK_benchMem(srcBuffer, benchedSize,
 +                     displayName, l, additionalParam,
 +                     fileSizes, nbFiles,
 +                     dictBuffer, dictBufferSize, &result);
 +        if (g_displayLevel == 1) {
 +            if (additionalParam)
 +                DISPLAY("%-3i%11i (%5.3f) %6.1f MB/s %6.1f MB/s  %s (p=%d)\n", -l, (int)result.cSize, result.ratio, result.cSpeed, result.dSpeed, displayName, additionalParam);
 +            else
 +                DISPLAY("%-3i%11i (%5.3f) %6.1f MB/s %6.1f MB/s  %s\n", -l, (int)result.cSize, result.ratio, result.cSpeed, result.dSpeed, displayName);
 +            total.cSize += result.cSize;
 +            total.cSpeed += result.cSpeed;
 +            total.dSpeed += result.dSpeed;
 +            total.ratio += result.ratio;
          }
 -        return;
      }
 -    BMK_benchMem(srcBuffer, benchedSize,
 -                 displayName, cLevel,
 -                 fileSizes, nbFiles,
 -                 dictBuffer, dictBufferSize);
 +    if (g_displayLevel == 1 && cLevelLast > cLevel)
 +    {
 +        total.cSize /= 1+cLevelLast-cLevel;
 +        total.cSpeed /= 1+cLevelLast-cLevel;
 +        total.dSpeed /= 1+cLevelLast-cLevel;
 +        total.ratio /= 1+cLevelLast-cLevel;
 +        DISPLAY("avg%11i (%5.3f) %6.1f MB/s %6.1f MB/s  %s\n", (int)total.cSize, total.ratio, total.cSpeed, total.dSpeed, displayName);            
 +    }
  }
  
  static U64 BMK_getTotalFileSize(const char** fileNamesTable, unsigned nbFiles)
@@@ -572,14 -497,14 +546,14 @@@ static void BMK_syntheticTest(int cLeve
  
  
  int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles,
 -                   const char* dictFileName, int cLevel)
 +                   const char* dictFileName, int cLevel, int cLevelLast, int additionalParam)
  {
-     double compressibility = (double)g_compressibilityDefault / 100;
+     double const compressibility = (double)g_compressibilityDefault / 100;
  
      if (nbFiles == 0)
 -        BMK_syntheticTest(cLevel, compressibility);
 +        BMK_syntheticTest(cLevel, cLevelLast, additionalParam, compressibility);
      else
 -        BMK_benchFileTable(fileNamesTable, nbFiles, dictFileName, cLevel);
 +        BMK_benchFileTable(fileNamesTable, nbFiles, dictFileName, cLevel, cLevelLast, additionalParam);
      return 0;
  }
  
index 5e6d3b18dfe855a5a327cc20c9ddabacb3e31b6e,6d62451bda2023949441e915c8eb0eb4972ae312..bc5ffa423e99522d3de6ae92868fcf4f44dc4f20
  
  /* Main function */
  int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles,
 -                   const char* dictFileName, int cLevel);
 +                   const char* dictFileName, int cLevel, int cLevelLast, int additionalParam);
  
  /* Set Parameters */
- void BMK_SetNbIterations(int nbLoops);
+ void BMK_SetNbIterations(unsigned nbLoops);
  void BMK_SetBlockSize(size_t blockSize);
 -
 +void BMK_setNotificationLevel(unsigned level);
  
index f6a2321ec50f3f6100d9cfef1cab45d708b35da7,b4afcf11286e21ce0fa42d5dad9be480abecd6c6..24cf95d3954dd48ace50a8b1339ea136fc7a9c2e
  
  #define KNUTH      2654435761U
  #define MAX_MEM    (1984 MB)
 -#define DEFAULT_CHUNKSIZE   (4<<20)
  
  #define COMPRESSIBILITY_DEFAULT 0.50
- static const size_t sampleSize = 10000000;
+ static const size_t g_sampleSize = 10000000;
  
  
- /**************************************
+ /*_************************************
  *  Macros
  **************************************/
  #define DISPLAY(...)  fprintf(stderr, __VA_ARGS__)
index c986caee3015b640e629c8535941a1e67bcea3b4,86d6bff788065bfe9b887a8faa0115ab7cec064a..a14fe26def13410c4119b0d8e21520830e4055f3
@@@ -331,17 -325,11 +333,17 @@@ int main(int argCount, const char** arg
                          dictSelect *= 10, dictSelect += *argument++ - '0';
                      break;
  
 -                    /* Pause at the end (hidden option) */
 -                case 'p': main_pause=1; argument++; break;
 -
 +                    /* Pause at the end (-p) or set an additional param (-p#) (hidden option) */
 +                case 'p': argument++; 
 +                    if ((*argument>='0') && (*argument<='9')) {
 +                        additionalParam = 0;
 +                        while ((*argument >= '0') && (*argument <= '9'))
 +                            additionalParam *= 10, additionalParam += *argument++ - '0';
 +                        continue;
 +                    }
 +                    main_pause=1; break;
                      /* unknown command */
-                 default : return badusage(programName);
+                 default : CLEAN_RETURN(badusage(programName));
                  }
              }
              continue;