From: inikep Date: Mon, 4 Apr 2016 10:10:00 +0000 (+0200) Subject: Merge from Cyan4973/dev060 X-Git-Tag: v0.6.0^2~17^2~17^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19bd48f516e1fef7898635fe99b424316ec9ccdc;p=thirdparty%2Fzstd.git Merge from Cyan4973/dev060 --- 19bd48f516e1fef7898635fe99b424316ec9ccdc diff --cc lib/zstd_compress.c index ddb816b18,6905dcbf6..1c07a173b --- a/lib/zstd_compress.c +++ b/lib/zstd_compress.c @@@ -183,13 -213,13 +214,13 @@@ size_t ZSTD_sizeofCCtx(ZSTD_compression 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 */ @@@ -259,9 -289,9 +291,9 @@@ size_t ZSTD_copyCCtx(ZSTD_CCtx* dstCCtx 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); } @@@ -309,13 -338,13 +340,13 @@@ static void ZSTD_reduceTable (U32* cons * 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); } } @@@ -776,12 -849,18 +851,13 @@@ MEM_STATIC void ZSTD_storeSeq(seqStore_ { #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); @@@ -1949,10 -2001,13 +2001,10 @@@ static size_t ZSTD_compress_generic (ZS 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; @@@ -1988,7 -2042,12 +2040,7 @@@ 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; } @@@ -2174,22 -2233,15 +2226,18 @@@ static size_t ZSTD_compress_insertDicti } } - 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); @@@ -2215,23 -2267,30 +2263,42 @@@ } - 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); @@@ -2451,13 -2522,18 +2530,15 @@@ static const ZSTD_compressionParameter /*! 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; } diff --cc lib/zstd_decompress.c index ef99175e8,fd9b40233..436058b52 --- a/lib/zstd_decompress.c +++ b/lib/zstd_decompress.c @@@ -844,14 -843,13 +843,13 @@@ static size_t ZSTD_decompressBlock_inte if (srcSize >= ZSTD_BLOCKSIZE_MAX) return ERROR(srcSize_wrong); - ZSTD_LOG_BLOCK("%p: ZSTD_decompressBlock_internal searchLength=%d\n", dctx->base, dctx->params.searchLength); + ZSTD_LOG_BLOCK("%p: ZSTD_decompressBlock_internal searchLength=%d\n", dctx->base, dctx->fParams.mml); /* Decode literals sub-block */ - litCSize = ZSTD_decodeLiteralsBlock(dctx, src, srcSize); - if (ZSTD_isError(litCSize)) return litCSize; - ip += litCSize; - srcSize -= litCSize; + { size_t const litCSize = ZSTD_decodeLiteralsBlock(dctx, src, srcSize); + if (ZSTD_isError(litCSize)) return litCSize; + ip += litCSize; + srcSize -= litCSize; } return ZSTD_decompressSequences(dctx, dst, dstCapacity, ip, srcSize); } diff --cc lib/zstd_internal.h index c0ff68ea8,ff2713408..49edb3109 --- a/lib/zstd_internal.h +++ b/lib/zstd_internal.h @@@ -97,19 -99,18 +97,17 @@@ typedef enum { bt_compressed, bt_raw, b #define MINMATCH 4 #define REPCODE_STARTVALUE 1 -#define HASHLOG3 17 #define Litbits 8 - #define MLbits 7 - #define LLbits 6 #define Offbits 5 #define MaxLit ((1< /* sleep */ -# include /* setpriority */ +# include +# include /* 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 # 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 ***************************************/ @@@ -236,22 -190,19 +237,20 @@@ typedef struc 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) @@@ -287,125 -238,115 +286,130 @@@ 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%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%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 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 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 */ @@@ -442,47 -383,20 +446,47 @@@ 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; + - 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)