benchmark uses ZSTD_duplicateCCtx()
This commit is contained in:
+20
-3
@@ -224,6 +224,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
|||||||
const size_t maxCompressedSize = ZSTD_compressBound(srcSize) + (maxNbBlocks * 1024); /* add some room for safety */
|
const size_t maxCompressedSize = ZSTD_compressBound(srcSize) + (maxNbBlocks * 1024); /* add some room for safety */
|
||||||
void* const compressedBuffer = malloc(maxCompressedSize);
|
void* const compressedBuffer = malloc(maxCompressedSize);
|
||||||
void* const resultBuffer = malloc(srcSize);
|
void* const resultBuffer = malloc(srcSize);
|
||||||
|
ZSTD_CCtx* refCtx = ZSTD_createCCtx();
|
||||||
ZSTD_CCtx* ctx = ZSTD_createCCtx();
|
ZSTD_CCtx* ctx = ZSTD_createCCtx();
|
||||||
ZSTD_DCtx* dctx = ZSTD_createDCtx();
|
ZSTD_DCtx* dctx = ZSTD_createDCtx();
|
||||||
U64 crcOrig = XXH64(srcBuffer, srcSize, 0);
|
U64 crcOrig = XXH64(srcBuffer, srcSize, 0);
|
||||||
@@ -233,7 +234,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
|||||||
if (strlen(displayName)>17) displayName += strlen(displayName)-17; /* can only display 17 characters */
|
if (strlen(displayName)>17) displayName += strlen(displayName)-17; /* can only display 17 characters */
|
||||||
|
|
||||||
/* Memory allocation & restrictions */
|
/* Memory allocation & restrictions */
|
||||||
if (!compressedBuffer || !resultBuffer || !blockTable || !ctx || !dctx)
|
if (!compressedBuffer || !resultBuffer || !blockTable || !refCtx || !ctx || !dctx)
|
||||||
EXM_THROW(31, "not enough memory");
|
EXM_THROW(31, "not enough memory");
|
||||||
|
|
||||||
/* Init blockTable data */
|
/* Init blockTable data */
|
||||||
@@ -291,12 +292,27 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
|||||||
milliTime = BMK_GetMilliStart();
|
milliTime = BMK_GetMilliStart();
|
||||||
while (BMK_GetMilliSpan(milliTime) < TIMELOOP)
|
while (BMK_GetMilliSpan(milliTime) < TIMELOOP)
|
||||||
{
|
{
|
||||||
|
ZSTD_compressBegin_advanced(refCtx, ZSTD_getParams(cLevel, dictBufferSize+blockSize));
|
||||||
|
ZSTD_compress_insertDictionary(refCtx, dictBuffer, dictBufferSize);
|
||||||
for (blockNb=0; blockNb<nbBlocks; blockNb++)
|
for (blockNb=0; blockNb<nbBlocks; blockNb++)
|
||||||
blockTable[blockNb].cSize = ZSTD_compress_usingDict(ctx,
|
{
|
||||||
|
ZSTD_duplicateCCtx(ctx, refCtx);
|
||||||
|
size_t rSize = ZSTD_compressContinue(ctx,
|
||||||
|
blockTable[blockNb].cPtr, blockTable[blockNb].cRoom,
|
||||||
|
blockTable[blockNb].srcPtr,blockTable[blockNb].srcSize);
|
||||||
|
if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_compressContinue() failed : %s", ZSTD_getErrorName(rSize));
|
||||||
|
blockTable[blockNb].cSize = rSize;
|
||||||
|
rSize = ZSTD_compressEnd(ctx,
|
||||||
|
blockTable[blockNb].cPtr + rSize,
|
||||||
|
blockTable[blockNb].cRoom - rSize);
|
||||||
|
if (ZSTD_isError(rSize)) EXM_THROW(2, "ZSTD_compressEnd() failed : %s", ZSTD_getErrorName(rSize));
|
||||||
|
blockTable[blockNb].cSize += rSize;
|
||||||
|
}
|
||||||
|
/*blockTable[blockNb].cSize = ZSTD_compress_usingDict(ctx,
|
||||||
blockTable[blockNb].cPtr, blockTable[blockNb].cRoom,
|
blockTable[blockNb].cPtr, blockTable[blockNb].cRoom,
|
||||||
blockTable[blockNb].srcPtr,blockTable[blockNb].srcSize,
|
blockTable[blockNb].srcPtr,blockTable[blockNb].srcSize,
|
||||||
dictBuffer, dictBufferSize,
|
dictBuffer, dictBufferSize,
|
||||||
cLevel);
|
cLevel);*/
|
||||||
nbLoops++;
|
nbLoops++;
|
||||||
}
|
}
|
||||||
milliTime = BMK_GetMilliSpan(milliTime);
|
milliTime = BMK_GetMilliSpan(milliTime);
|
||||||
@@ -358,6 +374,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
|||||||
/* clean up */
|
/* clean up */
|
||||||
free(compressedBuffer);
|
free(compressedBuffer);
|
||||||
free(resultBuffer);
|
free(resultBuffer);
|
||||||
|
ZSTD_freeCCtx(refCtx);
|
||||||
ZSTD_freeCCtx(ctx);
|
ZSTD_freeCCtx(ctx);
|
||||||
ZSTD_freeDCtx(dctx);
|
ZSTD_freeDCtx(dctx);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user