U32 nextToUpdate; /* index from which to continue dictionary update */
U32 nextToUpdate3; /* index from which to continue dictionary update */
U32 hashLog3; /* dispatch table : larger == faster, more memory */
+ U32 targetSrcSize; /* optimize compression for this source size */
U32 loadedDictEnd;
U32 stage;
ZSTD_parameters params;
zc->hbSize = 0;
zc->stage = 0;
zc->loadedDictEnd = 0;
+ zc->targetSrcSize = 0;
return 0;
}
dstCCtx->dictLimit = srcCCtx->dictLimit;
dstCCtx->lowLimit = srcCCtx->lowLimit;
dstCCtx->loadedDictEnd= srcCCtx->loadedDictEnd;
+ dstCCtx->targetSrcSize= srcCCtx->targetSrcSize;
/* copy entropy tables */
dstCCtx->flagStaticTables = srcCCtx->flagStaticTables;
}
}
+extern int g_additionalParam;
/*! ZSTD_compressBegin_advanced() :
* @return : 0, or an error code */
const void* dict, size_t dictSize,
ZSTD_parameters params)
{
-// printf("windowLog=%d hashLog=%d\n", params.windowLog, params.hashLog);
+// printf("windowLog=%d hashLog=%d targetSrcSize=%d\n", params.windowLog, params.hashLog, zc->targetSrcSize);
ZSTD_validateParams(¶ms);
- zc->hashLog3 = (params.searchLength==3) ? ZSTD_HASHLOG3 : 0;
-// if (zc->hashLog3 > params.windowLog) zc->hashLog3 = params.windowLog;
+ 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;
// printf("windowLog=%d hashLog=%d hashLog3=%d \n", params.windowLog, params.hashLog, zc->hashLog3);
{ size_t const errorCode = ZSTD_resetCCtx_advanced(zc, params);
}
+size_t ZSTD_compressBegin_targetSrcSize(ZSTD_CCtx* zc, const void* dict, size_t dictSize, size_t targetSrcSize, int compressionLevel)
+{
+ 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);
+}
+
size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* zc, const void* dict, size_t dictSize, int compressionLevel)
{
ZSTD_parameters params = ZSTD_getParams(compressionLevel, dictSize);
size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, const void* dict, size_t dictSize, int compressionLevel)
{
ZSTD_LOG_BLOCK("%p: ZSTD_compress_usingDict srcSize=%d dictSize=%d compressionLevel=%d\n", ctx->base, (int)srcSize, (int)dictSize, compressionLevel);
+ ctx->targetSrcSize = srcSize;
return ZSTD_compress_advanced(ctx, dst, dstCapacity, src, srcSize, dict, dictSize, ZSTD_getParams(compressionLevel, srcSize));
}
size_t ZSTD_compressCCtx (ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel)
{
ZSTD_LOG_BLOCK("%p: ZSTD_compressCCtx srcSize=%d compressionLevel=%d\n", ctx->base, (int)srcSize, compressionLevel);
+ ctx->targetSrcSize = srcSize;
return ZSTD_compress_advanced(ctx, dst, dstCapacity, src, srcSize, NULL, 0, ZSTD_getParams(compressionLevel, srcSize));
}
#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 */
/* *************************************
***************************************/
static U32 g_nbIterations = NBLOOPS;
static size_t g_blockSize = 0;
+int g_additionalParam = 0;
void BMK_setNotificationLevel(unsigned level) { g_displayLevel=level; }
+void BMK_setAdditionalParam(int additionalParam) { g_additionalParam=additionalParam; }
+
void BMK_SetNbIterations(unsigned nbLoops)
{
g_nbIterations = nbLoops;
for (nbLoops = 0 ; BMK_clockSpan(clockStart) < clockLoop ; nbLoops++) {
U32 blockNb;
-#if 0
- ZSTD_compressBegin_usingDict(refCtx, dictBuffer, dictBufferSize, cLevel);
-#else
- ZSTD_parameters params = ZSTD_getParams(cLevel, dictBufferSize ? dictBufferSize : blockSize);
- // printf("cLevel=%d dictBufferSize=%d srcSize=%d params.srcSize=%d \n", cLevel, (int)dictBufferSize, (int)blockTable[0].srcSize, (int)params.srcSize);
- params.srcSize = 0;
- ZSTD_compressBegin_advanced(refCtx, dictBuffer, dictBufferSize, params);
-#endif
-
+ ZSTD_compressBegin_targetSrcSize(refCtx, dictBuffer, dictBufferSize, blockSize, cLevel);
for (blockNb=0; blockNb<nbBlocks; blockNb++) {
size_t const rSize = ZSTD_compress_usingPreparedCCtx(ctx, refCtx,
blockTable[blockNb].cPtr, blockTable[blockNb].cRoom,
}
static void BMK_benchCLevel(void* srcBuffer, size_t benchedSize,
- const char* displayName, int cLevel, int cLevelLast, int additionalParam,
+ const char* displayName, int cLevel, int cLevelLast,
const size_t* fileSizes, unsigned nbFiles,
const void* dictBuffer, size_t dictBufferSize)
{
memset(&result, 0, sizeof(result));
memset(&total, 0, sizeof(total));
- if (g_displayLevel == 1 && !additionalParam)
+ 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;
fileSizes, nbFiles,
dictBuffer, dictBufferSize, &result);
if (g_displayLevel == 1) {
- if (additionalParam)
- DISPLAY("%-3i%11i (%5.3f) %6.1f MB/s %6.1f MB/s %s (p=%d)\n", -l, (int)result.cSize, result.ratio, result.cSpeed, result.dSpeed, displayName, additionalParam);
+ 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;
}
static void BMK_benchFileTable(const char** fileNamesTable, unsigned nbFiles,
- const char* dictFileName, int cLevel, int cLevelLast, int additionalParam)
+ const char* dictFileName, int cLevel, int cLevelLast)
{
void* srcBuffer;
size_t benchedSize;
else displayName = fileNamesTable[0];
BMK_benchCLevel(srcBuffer, benchedSize,
- displayName, cLevel, cLevelLast, additionalParam,
+ displayName, cLevel, cLevelLast,
fileSizes, nbFiles,
dictBuffer, dictBufferSize);
}
-static void BMK_syntheticTest(int cLevel, int cLevelLast, int additionalParam, double compressibility)
+static void BMK_syntheticTest(int cLevel, int cLevelLast, double compressibility)
{
char name[20] = {0};
size_t benchedSize = 10000000;
/* Bench */
snprintf (name, sizeof(name), "Synthetic %2u%%", (unsigned)(compressibility*100));
- BMK_benchCLevel(srcBuffer, benchedSize, name, cLevel, cLevelLast, additionalParam, &benchedSize, 1, NULL, 0);
+ BMK_benchCLevel(srcBuffer, benchedSize, name, cLevel, cLevelLast, &benchedSize, 1, NULL, 0);
/* clean up */
free(srcBuffer);
int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles,
- const char* dictFileName, int cLevel, int cLevelLast, int additionalParam)
+ const char* dictFileName, int cLevel, int cLevelLast)
{
double const compressibility = (double)g_compressibilityDefault / 100;
if (nbFiles == 0)
- BMK_syntheticTest(cLevel, cLevelLast, additionalParam, compressibility);
+ BMK_syntheticTest(cLevel, cLevelLast, compressibility);
else
- BMK_benchFileTable(fileNamesTable, nbFiles, dictFileName, cLevel, cLevelLast, additionalParam);
+ BMK_benchFileTable(fileNamesTable, nbFiles, dictFileName, cLevel, cLevelLast);
return 0;
}
nextArgumentIsMaxDict=0;
unsigned cLevel = 1;
unsigned cLevelLast = 1;
- int additionalParam = 0;
const char** filenameTable = (const char**)malloc(argCount * sizeof(const char*)); /* argCount >= 1 */
unsigned filenameIdx = 0;
const char* programName = argv[0];
unsigned dictSelect = g_defaultSelectivityLevel;
/* init */
- (void)additionalParam; (void)cLevelLast; (void)dictCLevel; /* not used when ZSTD_NOBENCH / ZSTD_NODICT set */
+ (void)cLevelLast; (void)dictCLevel; /* not used when ZSTD_NOBENCH / ZSTD_NODICT set */
if (filenameTable==NULL) { DISPLAY("not enough memory\n"); exit(1); }
displayOut = stderr;
/* Pick out program name from path. Don't rely on stdlib because of conflicting behavior */
cLevelLast = 0;
while ((*argument >= '0') && (*argument <= '9'))
cLevelLast *= 10, cLevelLast += *argument++ - '0';
- continue;
}
break;
#endif /* ZSTD_NOBENCH */
/* Pause at the end (-p) or set an additional param (-p#) (hidden option) */
case 'p': argument++;
if ((*argument>='0') && (*argument<='9')) {
- additionalParam = 0;
+ int additionalParam = 0;
while ((*argument >= '0') && (*argument <= '9'))
additionalParam *= 10, additionalParam += *argument++ - '0';
- continue;
+ BMK_setAdditionalParam(additionalParam);
+ } else {
+ main_pause=1;
}
- main_pause=1; break;
+ break;
/* unknown command */
default : CLEAN_RETURN(badusage(programName));
}
if (bench) {
#ifndef ZSTD_NOBENCH
BMK_setNotificationLevel(displayLevel);
- BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel, cLevelLast, additionalParam);
+ BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel, cLevelLast);
#endif
goto _end;
}