bench: fixed Visual warning regarding struct initialization
also : removed dependency on zstdmt_compress.h removed several unused macros fileio : small code refactoring to reduce some variable scope
This commit is contained in:
+26
-25
@@ -41,7 +41,6 @@
|
||||
#include "zstd.h"
|
||||
#include "datagen.h" /* RDG_genBuffer */
|
||||
#include "xxhash.h"
|
||||
#include "zstdmt_compress.h"
|
||||
|
||||
|
||||
/* *************************************
|
||||
@@ -189,7 +188,6 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
||||
size_t const maxCompressedSize = ZSTD_compressBound(srcSize) + (maxNbBlocks * 1024); /* add some room for safety */
|
||||
void* const compressedBuffer = malloc(maxCompressedSize);
|
||||
void* resultBuffer = malloc(srcSize);
|
||||
ZSTDMT_CCtx* const mtctx = ZSTDMT_createCCtx(g_nbThreads);
|
||||
ZSTD_CCtx* const ctx = ZSTD_createCCtx();
|
||||
ZSTD_DCtx* const dctx = ZSTD_createDCtx();
|
||||
size_t const loadedCompressedSize = srcSize;
|
||||
@@ -286,7 +284,6 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
||||
if (!cCompleted) { /* still some time to do compression tests */
|
||||
U64 const clockLoop = g_nbSeconds ? TIMELOOP_MICROSEC : 1;
|
||||
U32 nbLoops = 0;
|
||||
ZSTD_CDict* cdict = NULL;
|
||||
ZSTD_CCtx_setParameter(ctx, ZSTD_p_nbThreads, g_nbThreads);
|
||||
ZSTD_CCtx_setParameter(ctx, ZSTD_p_compressionLevel, cLevel);
|
||||
ZSTD_CCtx_setParameter(ctx, ZSTD_p_enableLongDistanceMatching, g_ldmFlag);
|
||||
@@ -308,27 +305,31 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
||||
do {
|
||||
U32 blockNb;
|
||||
for (blockNb=0; blockNb<nbBlocks; blockNb++) {
|
||||
size_t rSize;
|
||||
ZSTD_outBuffer out = { blockTable[blockNb].cPtr, blockTable[blockNb].cRoom, 0 };
|
||||
ZSTD_inBuffer in = { blockTable[blockNb].srcPtr, blockTable[blockNb].srcSize, 0 };
|
||||
size_t cError = 1;
|
||||
while (cError) {
|
||||
cError = ZSTD_compress_generic(ctx,
|
||||
size_t moreToFlush = 1;
|
||||
ZSTD_outBuffer out;
|
||||
ZSTD_inBuffer in;
|
||||
in.src = blockTable[blockNb].srcPtr;
|
||||
in.size = blockTable[blockNb].srcSize;
|
||||
in.pos = 0;
|
||||
out.dst = blockTable[blockNb].cPtr;
|
||||
out.size = blockTable[blockNb].cRoom;
|
||||
out.pos = 0;
|
||||
while (moreToFlush) {
|
||||
moreToFlush = ZSTD_compress_generic(ctx,
|
||||
&out, &in, ZSTD_e_end);
|
||||
if (ZSTD_isError(cError))
|
||||
if (ZSTD_isError(moreToFlush))
|
||||
EXM_THROW(1, "ZSTD_compress_generic() error : %s",
|
||||
ZSTD_getErrorName(cError));
|
||||
ZSTD_getErrorName(moreToFlush));
|
||||
}
|
||||
rSize = out.pos;
|
||||
blockTable[blockNb].cSize = rSize;
|
||||
blockTable[blockNb].cSize = out.pos;
|
||||
}
|
||||
nbLoops++;
|
||||
} while (UTIL_clockSpanMicro(clockStart) < clockLoop);
|
||||
ZSTD_freeCDict(cdict);
|
||||
{ U64 const clockSpanMicro = UTIL_clockSpanMicro(clockStart);
|
||||
if (clockSpanMicro < fastestC*nbLoops) fastestC = clockSpanMicro / nbLoops;
|
||||
totalCTime += clockSpanMicro;
|
||||
cCompleted = (totalCTime >= maxTime);
|
||||
{ U64 const loopDuration = UTIL_clockSpanMicro(clockStart);
|
||||
if (loopDuration < fastestC*nbLoops)
|
||||
fastestC = loopDuration / nbLoops;
|
||||
totalCTime += loopDuration;
|
||||
cCompleted = (totalCTime >= maxTime); /* end compression tests */
|
||||
} }
|
||||
|
||||
cSize = 0;
|
||||
@@ -336,15 +337,15 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
||||
ratio = (double)srcSize / (double)cSize;
|
||||
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 );
|
||||
marks[markNb], displayName, (U32)srcSize, (U32)cSize,
|
||||
ratio, (double)srcSize / fastestC );
|
||||
} else { /* g_decodeOnly */
|
||||
memcpy(compressedBuffer, srcBuffer, loadedCompressedSize);
|
||||
}
|
||||
|
||||
#if 0 /* disable decompression test */
|
||||
dCompleted=1;
|
||||
(void)totalDTime; (void)fastestD; (void)crcOrig; /* unused when decompression disabled */
|
||||
(void)totalDTime; (void)fastestD; (void)crcOrig; /* unused when decompression disabled */
|
||||
#else
|
||||
/* Decompression */
|
||||
if (!dCompleted) memset(resultBuffer, 0xD6, srcSize); /* warm result buffer */
|
||||
@@ -374,9 +375,10 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
||||
nbLoops++;
|
||||
} while (UTIL_clockSpanMicro(clockStart) < clockLoop);
|
||||
ZSTD_freeDDict(ddict);
|
||||
{ U64 const clockSpanMicro = UTIL_clockSpanMicro(clockStart);
|
||||
if (clockSpanMicro < fastestD*nbLoops) fastestD = clockSpanMicro / nbLoops;
|
||||
totalDTime += clockSpanMicro;
|
||||
{ U64 const loopDuration = UTIL_clockSpanMicro(clockStart);
|
||||
if (loopDuration < fastestD*nbLoops)
|
||||
fastestD = loopDuration / nbLoops;
|
||||
totalDTime += loopDuration;
|
||||
dCompleted = (totalDTime >= maxTime);
|
||||
} }
|
||||
|
||||
@@ -439,7 +441,6 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
||||
free(blockTable);
|
||||
free(compressedBuffer);
|
||||
free(resultBuffer);
|
||||
ZSTDMT_freeCCtx(mtctx);
|
||||
ZSTD_freeCCtx(ctx);
|
||||
ZSTD_freeDCtx(dctx);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user