From c5e1d295eeec565cdac42f69666bdde1e8ea02d2 Mon Sep 17 00:00:00 2001 From: inikep Date: Tue, 19 Apr 2016 09:37:59 +0200 Subject: [PATCH] bench.c: force at least one compression and decompression loop fix for -i0 with small files --- .gitignore | 1 + lib/zstd_opt.h | 5 +++-- programs/bench.c | 18 +++++++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 6ca7f8a7..8af4bbe9 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,4 @@ ipch/ .directory _codelite _zstdbench +zlib_wrapper diff --git a/lib/zstd_opt.h b/lib/zstd_opt.h index 553465e0..f584cf43 100644 --- a/lib/zstd_opt.h +++ b/lib/zstd_opt.h @@ -53,9 +53,10 @@ MEM_STATIC void ZSTD_rescaleFreqs(seqStore_t* ssPtr) { unsigned u; + ssPtr->cachedLiterals = NULL; + ssPtr->cachedPrice = ssPtr->cachedLitLength = 0; + if (ssPtr->litLengthSum == 0) { - ssPtr->cachedLiterals = NULL; - ssPtr->cachedPrice = ssPtr->cachedLitLength = 0; ssPtr->litSum = (2<litLengthSum = MaxLL+1; ssPtr->matchLengthSum = MaxML+1; diff --git a/programs/bench.c b/programs/bench.c index de9e16e9..2892ef74 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -307,7 +307,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, DISPLAYLEVEL(2, "\r%79s\r", ""); for (testNb = 1; testNb <= (g_nbIterations + !g_nbIterations); testNb++) { BMK_time_t clockStart, clockEnd; - U64 clockLoop = g_nbIterations ? TIMELOOP_S*1000000ULL : 10; + U64 clockLoop = g_nbIterations ? TIMELOOP_S*1000000ULL : 1; /* overheat protection */ if (BMK_clockSpan(coolTime, ticksPerSecond) > ACTIVEPERIOD_S*1000000ULL) { @@ -326,8 +326,8 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, while (BMK_getSpanTimeNano(ticksPerSecond, clockStart, clockEnd) == 0); BMK_getTime(clockStart); - { U32 nbLoops; - for (nbLoops = 0 ; BMK_clockSpan(clockStart, ticksPerSecond) < clockLoop ; nbLoops++) { + { U32 nbLoops = 0; + do { U32 blockNb; { ZSTD_parameters params; params.cParams = ZSTD_getCParams(cLevel, blockSize, dictBufferSize); @@ -342,7 +342,9 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, 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++; + } while (BMK_clockSpan(clockStart, ticksPerSecond) < clockLoop); { U64 const clockSpan = BMK_clockSpan(clockStart, ticksPerSecond); if (clockSpan < fastestC*nbLoops) fastestC = clockSpan / nbLoops; } } @@ -365,8 +367,8 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, while (BMK_getSpanTimeNano(ticksPerSecond, clockStart, clockEnd) == 0); BMK_getTime(clockStart); - { U32 nbLoops; - for (nbLoops = 0 ; BMK_clockSpan(clockStart, ticksPerSecond) < clockLoop ; nbLoops++) { + { U32 nbLoops = 0; + do { U32 blockNb; ZSTD_decompressBegin_usingDict(refDCtx, dictBuffer, dictBufferSize); for (blockNb=0; blockNb