static size_t ZSTD_resetCCtx_advanced (ZSTD_CCtx* zc,
ZSTD_parameters params)
{ /* note : params considered validated here */
- const size_t blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << params.windowLog);
- const U32 divider = (params.searchLength==3) ? 3 : 4;
+ const size_t blockSize = MIN(ZSTD_BLOCKSIZE_MAX, (size_t)1 << params.cParams.windowLog);
+ const U32 divider = (params.cParams.searchLength==3) ? 3 : 4;
const size_t maxNbSeq = blockSize / divider;
- const size_t tokenSpace = blockSize + 8*maxNbSeq;
- const size_t contentSize = (params.strategy == ZSTD_fast) ? 0 : (1 << params.contentLog);
- const size_t hSize = 1 << params.hashLog;
+ const size_t tokenSpace = blockSize + 11*maxNbSeq;
+ const size_t contentSize = (params.cParams.strategy == ZSTD_fast) ? 0 : (1 << params.cParams.contentLog);
+ const size_t hSize = 1 << params.cParams.hashLog;
- const size_t h3Size = (params.cParams.searchLength==3) ? (1 << HASHLOG3) : 0;
+ const size_t h3Size = (zc->hashLog3) ? 1 << zc->hashLog3 : 0;
const size_t tableSpace = (contentSize + hSize + h3Size) * sizeof(U32);
/* Check if workSpace is large enough, alloc a new one if needed */
ZSTD_resetCCtx_advanced(dstCCtx, srcCCtx->params);
/* copy tables */
- { const size_t contentSize = (srcCCtx->params.strategy == ZSTD_fast) ? 0 : (1 << srcCCtx->params.contentLog);
- const size_t hSize = 1 << srcCCtx->params.hashLog;
+ { const size_t contentSize = (srcCCtx->params.cParams.strategy == ZSTD_fast) ? 0 : (1 << srcCCtx->params.cParams.contentLog);
+ const size_t hSize = 1 << srcCCtx->params.cParams.hashLog;
- const size_t h3Size = (srcCCtx->params.cParams.searchLength == 3) ? (1 << HASHLOG3) : 0;
+ const size_t h3Size = (srcCCtx->hashLog3) ? 1 << srcCCtx->hashLog3 : 0;
const size_t tableSpace = (contentSize + hSize + h3Size) * sizeof(U32);
memcpy(dstCCtx->workSpace, srcCCtx->workSpace, tableSpace);
}
* rescale all indexes to avoid future overflow (indexes are U32) */
static void ZSTD_reduceIndex (ZSTD_CCtx* zc, const U32 reducerValue)
{
- { const U32 hSize = 1 << zc->params.hashLog;
+ { const U32 hSize = 1 << zc->params.cParams.hashLog;
ZSTD_reduceTable(zc->hashTable, hSize, reducerValue); }
- { const U32 contentSize = (zc->params.strategy == ZSTD_fast) ? 0 : (1 << zc->params.contentLog);
+ { const U32 contentSize = (zc->params.cParams.strategy == ZSTD_fast) ? 0 : (1 << zc->params.cParams.contentLog);
ZSTD_reduceTable(zc->contentTable, contentSize, reducerValue); }
- { const U32 h3Size = (zc->params.cParams.searchLength == 3) ? (1 << HASHLOG3) : 0;
+ { const U32 h3Size = (zc->hashLog3) ? 1 << zc->hashLog3 : 0;
ZSTD_reduceTable(zc->hashTable3, h3Size, reducerValue); }
}
{
#if 0 /* for debug */
static const BYTE* g_start = NULL;
+ const U32 pos = (U32)(literals - g_start);
if (g_start==NULL) g_start = literals;
- //if (literals - g_start == 8695)
- printf("pos %6u : %3u literals & match %3u bytes at distance %6u \n",
- (U32)(literals - g_start), (U32)litLength, (U32)matchCode+MINMATCH, (U32)offsetCode);
+ if ((pos > 200000000) && (pos < 200900000))
+ printf("Cpos %6u :%5u literals & match %3u bytes at distance %6u \n",
+ pos, (U32)litLength, (U32)matchCode+MINMATCH, (U32)offsetCode);
#endif
-#if ZSTD_OPT_DEBUG == 3
- if (offsetCode == 0) seqStorePtr->realRepSum++;
- seqStorePtr->realSeqSum++;
- seqStorePtr->realMatchSum += matchCode;
- seqStorePtr->realLitSum += litLength;
-#endif
+ ZSTD_statsUpdatePrices(&seqStorePtr->stats, litLength, literals, offsetCode, matchCode);
/* copy Literals */
ZSTD_wildcopy(seqStorePtr->lit, literals, litLength);
const BYTE* ip = (const BYTE*)src;
BYTE* const ostart = (BYTE*)dst;
BYTE* op = ostart;
- const U32 maxDist = 1 << zc->params.windowLog;
+ const U32 maxDist = 1 << zc->params.cParams.windowLog;
-#if ZSTD_OPT_DEBUG == 3
- seqStore_t* ssPtr = &zc->seqStore;
- static U32 priceFunc = 0;
- ssPtr->realMatchSum = ssPtr->realLitSum = ssPtr->realSeqSum = ssPtr->realRepSum = 1;
- ssPtr->priceFunc = priceFunc;
-#endif
+ ZSTD_stats_t* stats = &zc->seqStore.stats;
+
+ ZSTD_statsInit(stats);
while (remaining) {
size_t cSize;
op += cSize;
}
- ZSTD_statsPrint(stats, zc->params.searchLength);
-#if ZSTD_OPT_DEBUG == 3
- ssPtr->realMatchSum += ssPtr->realSeqSum * ((zc->params.searchLength == 3) ? 3 : 4);
- printf("avgMatchL=%.2f avgLitL=%.2f match=%.1f%% lit=%.1f%% reps=%d seq=%d priceFunc=%d\n", (float)ssPtr->realMatchSum/ssPtr->realSeqSum, (float)ssPtr->realLitSum/ssPtr->realSeqSum, 100.0*ssPtr->realMatchSum/(ssPtr->realMatchSum+ssPtr->realLitSum), 100.0*ssPtr->realLitSum/(ssPtr->realMatchSum+ssPtr->realLitSum), ssPtr->realRepSum, ssPtr->realSeqSum, ssPtr->priceFunc);
- priceFunc++;
-#endif
-
++ ZSTD_statsPrint(stats, zc->params.cParams.searchLength);
return op-ostart;
}
}
}
- extern int g_additionalParam;
--
- /*! ZSTD_compressBegin_advanced() :
+ /*! ZSTD_compressBegin_internal() :
* @return : 0, or an error code */
- size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* zc,
+ static size_t ZSTD_compressBegin_internal(ZSTD_CCtx* zc,
const void* dict, size_t dictSize,
- ZSTD_parameters params)
+ ZSTD_parameters params, U64 pledgedSrcSize)
{
- // printf("windowLog=%d hashLog=%d targetSrcSize=%d\n", params.windowLog, params.hashLog, zc->targetSrcSize);
- ZSTD_validateParams(¶ms);
- U32 hashLog3 = (!zc->targetSrcSize || zc->targetSrcSize >= 8192) ? ZSTD_HASHLOG3_MAX : ((zc->targetSrcSize >= 2048) ? ZSTD_HASHLOG3_MIN + 1 : ZSTD_HASHLOG3_MIN);
- zc->hashLog3 = (params.searchLength==3) ? hashLog3 : 0;
++ U32 hashLog3 = (pledgedSrcSize || pledgedSrcSize >= 8192) ? ZSTD_HASHLOG3_MAX : ((pledgedSrcSize >= 2048) ? ZSTD_HASHLOG3_MIN + 1 : ZSTD_HASHLOG3_MIN);
++ zc->hashLog3 = (params.cParams.searchLength==3) ? hashLog3 : 0;
+// printf("windowLog=%d hashLog=%d hashLog3=%d \n", params.windowLog, params.hashLog, zc->hashLog3);
+
{ size_t const errorCode = ZSTD_resetCCtx_advanced(zc, params);
- if (ZSTD_isError(errorCode)) return errorCode; }
+ if (ZSTD_isError(errorCode)) return errorCode; }
/* Write Frame Header into ctx headerBuffer */
MEM_writeLE32(zc->headerBuffer, ZSTD_MAGICNUMBER);
}
- size_t ZSTD_compressBegin_targetSrcSize(ZSTD_CCtx* zc, const void* dict, size_t dictSize, size_t targetSrcSize, int compressionLevel)
+ /*! ZSTD_compressBegin_advanced() :
+ * @return : 0, or an error code */
+ size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* zc,
+ const void* dict, size_t dictSize,
+ ZSTD_parameters params, U64 pledgedSrcSize)
{
- zc->targetSrcSize = dictSize ? dictSize : targetSrcSize;
- ZSTD_parameters params = ZSTD_getParams(compressionLevel, zc->targetSrcSize);
- params.srcSize = 0;
- ZSTD_LOG_BLOCK("%p: ZSTD_compressBegin_targetSrcSize compressionLevel=%d\n", zc->base, compressionLevel);
- return ZSTD_compressBegin_advanced(zc, dict, dictSize, params);
+ /* compression parameters verification and optimization */
+ { size_t const errorCode = ZSTD_checkCParams_advanced(params.cParams, pledgedSrcSize);
+ if (ZSTD_isError(errorCode)) return errorCode; }
+
+ return ZSTD_compressBegin_internal(zc, dict, dictSize, params, pledgedSrcSize);
}
+
size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* zc, const void* dict, size_t dictSize, int compressionLevel)
{
- ZSTD_parameters params = ZSTD_getParams(compressionLevel, dictSize);
- params.srcSize = 0;
+ ZSTD_parameters params;
+ params.cParams = ZSTD_getCParams(compressionLevel, 0, dictSize);
+ params.fParams.contentSizeFlag = 0;
+ ZSTD_adjustCParams(¶ms.cParams, 0, dictSize);
ZSTD_LOG_BLOCK("%p: ZSTD_compressBegin_usingDict compressionLevel=%d\n", zc->base, compressionLevel);
- return ZSTD_compressBegin_advanced(zc, dict, dictSize, params);
+ return ZSTD_compressBegin_internal(zc, dict, dictSize, params, 0);
}
++
++size_t ZSTD_compressBegin_targetSrcSize(ZSTD_CCtx* zc, const void* dict, size_t dictSize, size_t targetSrcSize, int compressionLevel)
++{
++ ZSTD_parameters params;
++ params.cParams = ZSTD_getCParams(compressionLevel, targetSrcSize, dictSize);
++ params.fParams.contentSizeFlag = 1;
++ ZSTD_adjustCParams(¶ms.cParams, targetSrcSize, dictSize);
++ ZSTD_LOG_BLOCK("%p: ZSTD_compressBegin_targetSrcSize compressionLevel=%d\n", zc->base, compressionLevel);
++ return ZSTD_compressBegin_internal(zc, dict, dictSize, params, targetSrcSize);
++}
++
++
size_t ZSTD_compressBegin(ZSTD_CCtx* zc, int compressionLevel)
{
ZSTD_LOG_BLOCK("%p: ZSTD_compressBegin compressionLevel=%d\n", zc->base, compressionLevel);
/*! ZSTD_getParams() :
* @return ZSTD_parameters structure for a selected compression level and srcSize.
* `srcSize` value is optional, select 0 if not known */
- ZSTD_parameters ZSTD_getParams(int compressionLevel, U64 srcSize)
+ ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, U64 srcSize, size_t dictSize)
{
- ZSTD_parameters result;
- int tableID = ((srcSize-1) <= 256 KB) + ((srcSize-1) <= 128 KB) + ((srcSize-1) <= 16 KB); /* intentional underflow for srcSizeHint == 0 */
+ ZSTD_compressionParameters cp;
+ size_t addedSize = srcSize ? 0 : 500;
+ U64 const rSize = srcSize+dictSize ? srcSize+dictSize+addedSize : (U64)-1;
+ U32 const tableID = (rSize <= 256 KB) + (rSize <= 128 KB) + (rSize <= 16 KB); /* intentional underflow for srcSizeHint == 0 */
if (compressionLevel<=0) compressionLevel = 1;
if (compressionLevel > ZSTD_MAX_CLEVEL) compressionLevel = ZSTD_MAX_CLEVEL;
- result = ZSTD_defaultParameters[tableID][compressionLevel];
- result.srcSize = srcSize;
- return result;
-#if ZSTD_OPT_DEBUG >= 1
- tableID=0;
-#endif
+ cp = ZSTD_defaultCParameters[tableID][compressionLevel];
+ if (cp.windowLog > ZSTD_WINDOWLOG_MAX) cp.windowLog = ZSTD_WINDOWLOG_MAX; /* auto-correction, for 32-bits mode */
+ return cp;
}
/* sleep : posix - windows - others */
#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
-# include <unistd.h> /* sleep */
-# include <sys/resource.h> /* setpriority */
+# include <unistd.h>
+# include <sys/resource.h> /* setpriority */
# define BMK_sleep(s) sleep(s)
-# define HIGH_PRIORITY setpriority(PRIO_PROCESS, 0, -20)
+# define mili_sleep(mili) { struct timespec t; t.tv_sec=0; t.tv_nsec=mili*1000000ULL; nanosleep(&t, NULL); }
- # define setHighPriority() setpriority(PRIO_PROCESS, 0, -20)
++# define SET_HIGH_PRIORITY setpriority(PRIO_PROCESS, 0, -20)
#elif defined(_WIN32)
# include <windows.h>
# define BMK_sleep(s) Sleep(1000*s)
-# define HIGH_PRIORITY SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
+# define mili_sleep(mili) Sleep(mili)
- # define setHighPriority() SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)
++# define SET_HIGH_PRIORITY SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)
#else
# define BMK_sleep(s) /* disabled */
-# define HIGH_PRIORITY
+# define mili_sleep(mili) /* disabled */
- # define setHighPriority() /* disabled */
++# define SET_HIGH_PRIORITY /* disabled */
+#endif
+
+#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))
+ typedef clock_t BMK_time_t;
+# define BMK_initTimer(ticksPerSecond) ticksPerSecond=0
+# define BMK_getTime(x) x = clock()
+# define BMK_getSpanTimeMicro(ticksPerSecond, clockStart, clockEnd) (1000000ULL * (clockEnd - clockStart) / CLOCKS_PER_SEC)
+# define BMK_getSpanTimeNano(ticksPerSecond, clockStart, clockEnd) (1000000000ULL * (clockEnd - clockStart) / CLOCKS_PER_SEC)
+#elif defined(_WIN32)
+ typedef LARGE_INTEGER BMK_time_t;
+# define BMK_initTimer(x) if (!QueryPerformanceFrequency(&x)) { fprintf(stderr, "ERROR: QueryPerformance not present\n"); }
+# define BMK_getTime(x) QueryPerformanceCounter(&x)
+# define BMK_getSpanTimeMicro(ticksPerSecond, clockStart, clockEnd) (1000000ULL*(clockEnd.QuadPart - clockStart.QuadPart)/ticksPerSecond.QuadPart)
+# define BMK_getSpanTimeNano(ticksPerSecond, clockStart, clockEnd) (1000000000ULL*(clockEnd.QuadPart - clockStart.QuadPart)/ticksPerSecond.QuadPart)
+#else
+ typedef int BMK_time_t;
+# define BMK_initTimer(ticksPerSecond) ticksPerSecond=0
+# define BMK_getTimeMicro(clockStart) clockStart=1
+# define BMK_getSpanTimeMicro(ticksPerSecond, clockStart, clockEnd) (TIMELOOP_S*1000000ULL+clockEnd-clockStart)
+# define BMK_getSpanTimeNano(ticksPerSecond, clockStart, clockEnd) (TIMELOOP_S*1000000000ULL+clockEnd-clockStart)
#endif
#include "mem.h"
#include "zstd_static.h"
+#include "zstd_internal.h" /* ZSTD_compressBegin_targetSrcSize */
+#include "datagen.h" /* RDG_genBuffer */
#include "xxhash.h"
-#include "datagen.h" /* RDG_genBuffer */
+
+
/* *************************************
* Compiler specifics
***************************************/
static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
const char* displayName, int cLevel,
const size_t* fileSizes, U32 nbFiles,
- const void* dictBuffer, size_t dictBufferSize)
+ const void* dictBuffer, size_t dictBufferSize, benchResult_t *result)
{
- const size_t blockSize = (g_blockSize ? g_blockSize : srcSize) + (!srcSize); /* avoid div by 0 */
- const U32 maxNbBlocks = (U32) ((srcSize + (blockSize-1)) / blockSize) + nbFiles;
+ size_t const blockSize = (g_blockSize ? g_blockSize : srcSize) + (!srcSize); /* avoid div by 0 */
+ U32 const maxNbBlocks = (U32) ((srcSize + (blockSize-1)) / blockSize) + nbFiles;
blockParam_t* const blockTable = (blockParam_t*) malloc(maxNbBlocks * sizeof(blockParam_t));
- const size_t maxCompressedSize = ZSTD_compressBound(srcSize) + (maxNbBlocks * 1024); /* add some room for safety */
+ size_t const maxCompressedSize = ZSTD_compressBound(srcSize) + (maxNbBlocks * 1024); /* add some room for safety */
void* const compressedBuffer = malloc(maxCompressedSize);
void* const resultBuffer = malloc(srcSize);
ZSTD_CCtx* refCtx = ZSTD_createCCtx();
ZSTD_CCtx* ctx = ZSTD_createCCtx();
ZSTD_DCtx* refDCtx = ZSTD_createDCtx();
ZSTD_DCtx* dctx = ZSTD_createDCtx();
-
- U64 const crcOrig = XXH64(srcBuffer, srcSize, 0);
U32 nbBlocks;
+ BMK_time_t ticksPerSecond;
/* checks */
if (!compressedBuffer || !resultBuffer || !blockTable || !refCtx || !ctx || !refDCtx || !dctx)
RDG_genBuffer(compressedBuffer, maxCompressedSize, 0.10, 0.50, 1);
/* Bench */
- { size_t cSize = 0;
- double fastestC = 100000000., fastestD = 100000000.;
- double ratio = 0.;
+ { double fastestC = 100000000., fastestD = 100000000.;
+ U64 const crcOrig = XXH64(srcBuffer, srcSize, 0);
- clock_t coolTime = clock();
+ U64 crcCheck = 0;
+ BMK_time_t coolTime;
U32 testNb;
++ size_t cSize = 0;
++ double ratio = 0.;
- DISPLAY("\r%79s\r", "");
+ BMK_getTime(coolTime);
+ DISPLAYLEVEL(2, "\r%79s\r", "");
for (testNb = 1; testNb <= (g_nbIterations + !g_nbIterations); testNb++) {
- int nbLoops;
- size_t cSize;
- double ratio = 0.;
- clock_t clockStart;
- clock_t const clockLoop = g_nbIterations ? TIMELOOP_S * CLOCKS_PER_SEC : 10;
+ BMK_time_t clockStart, clockEnd;
- U64 clockSpan;
- U64 const clockLoop = g_nbIterations ? TIMELOOP_S*1000000ULL : 10;
++ U64 clockLoop = g_nbIterations ? TIMELOOP_S*1000000ULL : 10;
/* overheat protection */
- if (BMK_clockSpan(coolTime) > ACTIVEPERIOD_S * CLOCKS_PER_SEC) {
+ if (BMK_clockSpan(coolTime, ticksPerSecond) > ACTIVEPERIOD_S*1000000ULL) {
DISPLAY("\rcooling down ... \r");
BMK_sleep(COOLPERIOD_S);
- coolTime = clock();
+ BMK_getTime(coolTime);
}
/* Compression */
- 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();
+ mili_sleep(1); /* give processor time to other processes */
+ BMK_getTime(clockStart);
+ do { BMK_getTime(clockEnd); }
+ while (BMK_getSpanTimeNano(ticksPerSecond, clockStart, clockEnd) == 0);
+ BMK_getTime(clockStart);
+
- for (nbLoops = 0 ; BMK_clockSpan(clockStart, ticksPerSecond) < clockLoop ; nbLoops++) {
- U32 blockNb;
- ZSTD_compressBegin_targetSrcSize(refCtx, dictBuffer, dictBufferSize, blockSize, cLevel);
- for (blockNb=0; blockNb<nbBlocks; blockNb++) {
- 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;
+ { U32 nbLoops;
- for (nbLoops = 0 ; BMK_clockSpan(clockStart) < clockLoop ; nbLoops++) {
++ for (nbLoops = 0 ; BMK_clockSpan(clockStart, ticksPerSecond) < clockLoop ; nbLoops++) {
+ U32 blockNb;
- ZSTD_compressBegin_usingDict(refCtx, dictBuffer, dictBufferSize, cLevel);
++ ZSTD_compressBegin_targetSrcSize(refCtx, dictBuffer, dictBufferSize, blockSize, cLevel);
++ // ZSTD_compressBegin_usingDict(refCtx, dictBuffer, dictBufferSize, cLevel);
+ for (blockNb=0; blockNb<nbBlocks; blockNb++) {
+ 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;
+ } }
- { clock_t const clockSpan = BMK_clockSpan(clockStart);
++ { U64 const clockSpan = BMK_clockSpan(clockStart, ticksPerSecond);
+ if ((double)clockSpan < fastestC*nbLoops) fastestC = (double)clockSpan / nbLoops;
} }
- clockSpan = BMK_clockSpan(clockStart, ticksPerSecond);
- if ((double)clockSpan < fastestC*nbLoops) fastestC = (double)clockSpan / nbLoops;
cSize = 0;
{ U32 blockNb; for (blockNb=0; blockNb<nbBlocks; blockNb++) cSize += blockTable[blockNb].cSize; }
ratio = (double)srcSize / (double)cSize;
- 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) );
+ (double)srcSize / fastestC );
+ (void)fastestD; (void)crcOrig; /* unused when decompression disabled */
#if 1
/* Decompression */
memset(resultBuffer, 0xD6, srcSize); /* warm result buffer */
- clockStart = clock();
- while (clock() == clockStart);
- clockStart = clock();
+ mili_sleep(1); /* give processor time to other processes */
+ BMK_getTime(clockStart);
+ do { BMK_getTime(clockEnd); }
+ while (BMK_getSpanTimeNano(ticksPerSecond, clockStart, clockEnd) == 0);
+ BMK_getTime(clockStart);
- for (nbLoops = 0 ; BMK_clockSpan(clockStart, ticksPerSecond) < clockLoop ; nbLoops++) {
- U32 blockNb;
- ZSTD_decompressBegin_usingDict(refDCtx, dictBuffer, dictBufferSize);
- for (blockNb=0; blockNb<nbBlocks; blockNb++) {
- size_t regenSize = ZSTD_decompress_usingPreparedDCtx(dctx, refDCtx,
- blockTable[blockNb].resPtr, blockTable[blockNb].srcSize,
- blockTable[blockNb].cPtr, blockTable[blockNb].cSize);
- if (ZSTD_isError(regenSize)) {
- DISPLAY("ZSTD_decompress_usingPreparedDCtx() failed on block %u : %s",
- blockNb, ZSTD_getErrorName(regenSize));
- goto _findError;
- }
- blockTable[blockNb].resSize = regenSize;
+ { U32 nbLoops;
- for (nbLoops = 0 ; BMK_clockSpan(clockStart) < clockLoop ; nbLoops++) {
++ for (nbLoops = 0 ; BMK_clockSpan(clockStart, ticksPerSecond) < clockLoop ; nbLoops++) {
+ U32 blockNb;
+ ZSTD_decompressBegin_usingDict(refDCtx, dictBuffer, dictBufferSize);
+ for (blockNb=0; blockNb<nbBlocks; blockNb++) {
+ size_t const regenSize = ZSTD_decompress_usingPreparedDCtx(dctx, refDCtx,
+ blockTable[blockNb].resPtr, blockTable[blockNb].srcSize,
+ blockTable[blockNb].cPtr, blockTable[blockNb].cSize);
+ if (ZSTD_isError(regenSize)) {
+ DISPLAY("ZSTD_decompress_usingPreparedDCtx() failed on block %u : %s \n",
+ blockNb, ZSTD_getErrorName(regenSize));
- clockStart -= clockLoop+1; /* force immediate test end */
++ clockLoop = 0; /* force immediate test end */
+ break;
+ }
+ blockTable[blockNb].resSize = regenSize;
+ } }
- { clock_t const clockSpan = BMK_clockSpan(clockStart);
++ { U64 const clockSpan = BMK_clockSpan(clockStart, ticksPerSecond);
+ if ((double)clockSpan < fastestD*nbLoops) fastestD = (double)clockSpan / nbLoops;
} }
- clockSpan = BMK_clockSpan(clockStart, ticksPerSecond);
- 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) );
+ (double)srcSize / fastestC,
+ (double)srcSize / fastestD );
/* CRC Checking */
- _findError:
- crcCheck = XXH64(resultBuffer, srcSize, 0);
- if (crcOrig!=crcCheck) {
- size_t u;
- DISPLAY("\n!!! WARNING !!! %14s : Invalid Checksum : %x != %x\n", displayName, (unsigned)crcOrig, (unsigned)crcCheck);
- for (u=0; u<srcSize; u++) {
- if (((const BYTE*)srcBuffer)[u] != ((const BYTE*)resultBuffer)[u]) {
- U32 segNb, bNb, pos;
- size_t bacc = 0;
- printf("Decoding error at pos %u ", (U32)u);
- for (segNb = 0; segNb < nbBlocks; segNb++) {
- if (bacc + blockTable[segNb].srcSize > u) break;
- bacc += blockTable[segNb].srcSize;
- { U64 const crcCheck = XXH64(resultBuffer, srcSize, 0);
++ { crcCheck = XXH64(resultBuffer, srcSize, 0);
+ if (crcOrig!=crcCheck) {
+ size_t u;
+ DISPLAY("!!! WARNING !!! %14s : Invalid Checksum : %x != %x \n", displayName, (unsigned)crcOrig, (unsigned)crcCheck);
+ for (u=0; u<srcSize; u++) {
+ if (((const BYTE*)srcBuffer)[u] != ((const BYTE*)resultBuffer)[u]) {
+ U32 segNb, bNb, pos;
+ size_t bacc = 0;
+ DISPLAY("Decoding error at pos %u ", (U32)u);
+ for (segNb = 0; segNb < nbBlocks; segNb++) {
+ if (bacc + blockTable[segNb].srcSize > u) break;
+ bacc += blockTable[segNb].srcSize;
+ }
+ pos = (U32)(u - bacc);
+ bNb = pos / (128 KB);
+ DISPLAY("(block %u, sub %u, pos %u) \n", segNb, bNb, pos);
+ break;
}
- pos = (U32)(u - bacc);
- bNb = pos / (128 KB);
- printf("(block %u, sub %u, pos %u) \n", segNb, bNb, pos);
- break;
- }
- if (u==srcSize-1) { /* should never happen */
- printf("no difference detected\n");
- } }
- break;
- } /* if (crcOrig!=crcCheck) */
+ if (u==srcSize-1) { /* should never happen */
+ DISPLAY("no difference detected\n");
+ } }
+ break;
+ } } /* CRC Checking */
#endif
} /* for (testNb = 1; testNb <= (g_nbIterations + !g_nbIterations); testNb++) */
- DISPLAY("%2i#\n", cLevel);
+
+ if (crcOrig == crcCheck) {
+ result->ratio = ratio;
+ result->cSize = cSize;
+ result->cSpeed = (double)srcSize / fastestC;
+ result->dSpeed = (double)srcSize / fastestD;
+ }
+ DISPLAYLEVEL(2, "%2i#\n", cLevel);
} /* Bench */
/* clean up */
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;
+
- setHighPriority();
++ SET_HIGH_PRIORITY;
+
+ 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 && !g_additionalParam)
+ 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,
+ fileSizes, nbFiles,
+ dictBuffer, dictBufferSize, &result);
+ if (g_displayLevel == 1) {
+ if (g_additionalParam)
+ DISPLAY("%-3i%11i (%5.3f) %6.1f MB/s %6.1f MB/s %s (param=%d)\n", -l, (int)result.cSize, result.ratio, result.cSpeed, result.dSpeed, displayName, g_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)