From a9febe81ae334d5cb5920144d1b9e3a2cd04f6f9 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 1 Aug 2016 13:37:17 +0200 Subject: [PATCH] changed bench behavior for slow compression levels --- programs/bench.c | 33 ++++++++++++++++++++++----------- programs/zstd.1 | 2 +- programs/zstdcli.c | 2 +- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/programs/bench.c b/programs/bench.c index f4bff8835..98e79add7 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -190,13 +190,18 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, { U64 fastestC = (U64)(-1LL), fastestD = (U64)(-1LL); U64 const crcOrig = XXH64(srcBuffer, srcSize, 0); UTIL_time_t coolTime; - U32 testNb; + U64 const maxTime = (g_nbIterations * TIMELOOP_MICROSEC) + 100; + U64 totalCTime=0, totalDTime=0; + U32 cCompleted=0, dCompleted=0; +# define NB_MARKS 4 + const char* const marks[NB_MARKS] = { " |", " /", " =", "\\" }; + U32 markNb = 0; size_t cSize = 0; double ratio = 0.; UTIL_getTime(&coolTime); DISPLAYLEVEL(2, "\r%79s\r", ""); - for (testNb = 1; testNb <= (g_nbIterations + !g_nbIterations); testNb++) { + while (!cCompleted | !dCompleted) { UTIL_time_t clockStart; U64 clockLoop = g_nbIterations ? TIMELOOP_MICROSEC : 1; @@ -208,15 +213,14 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, } /* Compression */ - DISPLAYLEVEL(2, "%2i-%-17.17s :%10u ->\r", testNb, displayName, (U32)srcSize); - memset(compressedBuffer, 0xE5, maxCompressedSize); /* warm up and erase result buffer */ + DISPLAYLEVEL(2, "%2s-%-17.17s :%10u ->\r", marks[markNb], displayName, (U32)srcSize); + if (!cCompleted) memset(compressedBuffer, 0xE5, maxCompressedSize); /* warm up and erase result buffer */ UTIL_sleepMilli(1); /* give processor time to other processes */ UTIL_waitForNextTick(ticksPerSecond); UTIL_getTime(&clockStart); - { //size_t const refSrcSize = (nbBlocks == 1) ? srcSize : 0; - //ZSTD_parameters const zparams = ZSTD_getParams(cLevel, refSrcSize, dictBufferSize); + if (!cCompleted) { /* still some time to do compression tests */ ZSTD_parameters const zparams = ZSTD_getParams(cLevel, blockSize, dictBufferSize); ZSTD_customMem const cmem = { NULL, NULL, NULL }; U32 nbLoops = 0; @@ -237,13 +241,16 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, ZSTD_freeCDict(cdict); { U64 const clockSpan = UTIL_clockSpanMicro(clockStart, ticksPerSecond); if (clockSpan < fastestC*nbLoops) fastestC = clockSpan / nbLoops; + totalCTime += clockSpan; + cCompleted = totalCTime>maxTime; } } cSize = 0; { U32 blockNb; for (blockNb=0; blockNb%10u (%5.3f),%6.1f MB/s\r", - testNb, displayName, (U32)srcSize, (U32)cSize, ratio, + markNb = (markNb+1) % NB_MARKS; + DISPLAYLEVEL(2, "%2s-%-17.17s :%10u ->%10u (%5.3f),%6.1f MB/s\r", + marks[markNb], displayName, (U32)srcSize, (U32)cSize, ratio, (double)srcSize / fastestC ); (void)fastestD; (void)crcOrig; /* unused when decompression disabled */ @@ -255,7 +262,8 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, UTIL_waitForNextTick(ticksPerSecond); UTIL_getTime(&clockStart); - { U32 nbLoops = 0; + if (!dCompleted) { + U32 nbLoops = 0; ZSTD_DDict* ddict = ZSTD_createDDict(dictBuffer, dictBufferSize); if (!ddict) EXM_THROW(2, "ZSTD_createDDict() allocation failure"); do { @@ -278,10 +286,13 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, ZSTD_freeDDict(ddict); { U64 const clockSpan = UTIL_clockSpanMicro(clockStart, ticksPerSecond); if (clockSpan < fastestD*nbLoops) fastestD = clockSpan / nbLoops; + totalDTime += clockSpan; + dCompleted = totalDTime>maxTime; } } - 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, + markNb = (markNb+1) % NB_MARKS; + DISPLAYLEVEL(2, "%2s-%-17.17s :%10u ->%10u (%5.3f),%6.1f MB/s ,%6.1f MB/s\r", + marks[markNb], displayName, (U32)srcSize, (U32)cSize, ratio, (double)srcSize / fastestC, (double)srcSize / fastestD ); diff --git a/programs/zstd.1 b/programs/zstd.1 index d2dfc3c14..0a0ad629d 100644 --- a/programs/zstd.1 +++ b/programs/zstd.1 @@ -128,7 +128,7 @@ Typical gains range from ~10% (at 64KB) to x5 better (at <1KB). benchmark file(s) using compression level # .TP .B \-i# - iteration loops [1-9](default : 3), benchmark mode only + minimum evaluation time, in seconds (default : 3s), benchmark mode only .TP .B \-B# cut file into independent blocks of size # (default: no block) diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 466823222..1e5536134 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -165,7 +165,7 @@ static int usage_advanced(const char* programName) DISPLAY( "Benchmark arguments :\n"); DISPLAY( " -b# : benchmark file(s), using # compression level (default : 1) \n"); DISPLAY( " -e# : test all compression levels from -bX to # (default: 1)\n"); - DISPLAY( " -i# : iteration loops [1-9](default : 3)\n"); + DISPLAY( " -i# : minimum evaluation time in seconds (default : 3s)\n"); DISPLAY( " -B# : cut file into independent blocks of size # (default: no block)\n"); #endif return 0;