updated paramgrill

This commit is contained in:
Yann Collet 2016-07-12 13:42:10 +02:00
parent bdf554b481
commit a43a854cdb
2 changed files with 49 additions and 57 deletions

View File

@ -2939,7 +2939,7 @@ unsigned ZSTD_maxCLevel(void) { return ZSTD_MAX_CLEVEL; }
static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEVEL+1] = { static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEVEL+1] = {
{ /* "default" */ { /* "default" */
/* W, C, H, S, L, TL, strat */ /* W, C, H, S, L, TL, strat */
{ 0, 0, 0, 0, 0, 0, ZSTD_fast }, /* level 0 - never used */ { 18, 12, 12, 1, 7, 4, ZSTD_fast }, /* level 0 - not used */
{ 19, 13, 14, 1, 7, 4, ZSTD_fast }, /* level 1 */ { 19, 13, 14, 1, 7, 4, ZSTD_fast }, /* level 1 */
{ 19, 15, 16, 1, 6, 4, ZSTD_fast }, /* level 2 */ { 19, 15, 16, 1, 6, 4, ZSTD_fast }, /* level 2 */
{ 20, 16, 17, 1, 6, 4, ZSTD_dfast }, /* level 3 */ { 20, 16, 17, 1, 6, 4, ZSTD_dfast }, /* level 3 */
@ -2965,7 +2965,7 @@ static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEV
}, },
{ /* for srcSize <= 256 KB */ { /* for srcSize <= 256 KB */
/* W, C, H, S, L, T, strat */ /* W, C, H, S, L, T, strat */
{ 0, 0, 0, 0, 0, 0, ZSTD_fast }, /* level 0 */ { 18, 12, 12, 1, 7, 4, ZSTD_fast }, /* level 0 - not used */
{ 18, 13, 14, 1, 6, 4, ZSTD_fast }, /* level 1 */ { 18, 13, 14, 1, 6, 4, ZSTD_fast }, /* level 1 */
{ 18, 15, 17, 1, 5, 4, ZSTD_fast }, /* level 2 */ { 18, 15, 17, 1, 5, 4, ZSTD_fast }, /* level 2 */
{ 18, 13, 15, 1, 5, 4, ZSTD_greedy }, /* level 3.*/ { 18, 13, 15, 1, 5, 4, ZSTD_greedy }, /* level 3.*/
@ -2991,7 +2991,7 @@ static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEV
}, },
{ /* for srcSize <= 128 KB */ { /* for srcSize <= 128 KB */
/* W, C, H, S, L, T, strat */ /* W, C, H, S, L, T, strat */
{ 0, 0, 0, 0, 0, 0, ZSTD_fast }, /* level 0 - never used */ { 17, 12, 12, 1, 7, 4, ZSTD_fast }, /* level 0 - not used */
{ 17, 12, 13, 1, 6, 4, ZSTD_fast }, /* level 1 */ { 17, 12, 13, 1, 6, 4, ZSTD_fast }, /* level 1 */
{ 17, 13, 16, 1, 5, 4, ZSTD_fast }, /* level 2 */ { 17, 13, 16, 1, 5, 4, ZSTD_fast }, /* level 2 */
{ 17, 13, 14, 2, 5, 4, ZSTD_greedy }, /* level 3 */ { 17, 13, 14, 2, 5, 4, ZSTD_greedy }, /* level 3 */
@ -3017,7 +3017,7 @@ static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEV
}, },
{ /* for srcSize <= 16 KB */ { /* for srcSize <= 16 KB */
/* W, C, H, S, L, T, strat */ /* W, C, H, S, L, T, strat */
{ 0, 0, 0, 0, 0, 0, ZSTD_fast }, /* level 0 -- never used */ { 14, 12, 12, 1, 7, 4, ZSTD_fast }, /* level 0 - not used */
{ 14, 14, 14, 1, 4, 4, ZSTD_fast }, /* level 1 */ { 14, 14, 14, 1, 4, 4, ZSTD_fast }, /* level 1 */
{ 14, 14, 15, 1, 4, 4, ZSTD_fast }, /* level 2 */ { 14, 14, 15, 1, 4, 4, ZSTD_fast }, /* level 2 */
{ 14, 14, 14, 4, 4, 4, ZSTD_greedy }, /* level 3.*/ { 14, 14, 14, 4, 4, 4, ZSTD_greedy }, /* level 3.*/
@ -3065,7 +3065,7 @@ ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long l
} }
/*! ZSTD_getParams() : /*! ZSTD_getParams() :
* same as ZSTD_getCParams(), but @return a `ZSTD_parameters` object instead of a `ZSTD_compressionParameters`. * same as ZSTD_getCParams(), but @return a `ZSTD_parameters` object (instead of `ZSTD_compressionParameters`).
* All fields of `ZSTD_frameParameters` are set to default (0) */ * All fields of `ZSTD_frameParameters` are set to default (0) */
ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSize, size_t dictSize) { ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSize, size_t dictSize) {
ZSTD_parameters params; ZSTD_parameters params;

View File

@ -363,6 +363,7 @@ static size_t BMK_benchParam(BMK_result_t* resultPtr,
const char* g_stratName[] = { "ZSTD_fast ", const char* g_stratName[] = { "ZSTD_fast ",
"ZSTD_dfast ",
"ZSTD_greedy ", "ZSTD_greedy ",
"ZSTD_lazy ", "ZSTD_lazy ",
"ZSTD_lazy2 ", "ZSTD_lazy2 ",
@ -635,13 +636,12 @@ static void BMK_selectRandomStart(
static void BMK_benchMem(void* srcBuffer, size_t srcSize) static void BMK_benchMem(void* srcBuffer, size_t srcSize)
{ {
ZSTD_CCtx* ctx = ZSTD_createCCtx(); ZSTD_CCtx* const ctx = ZSTD_createCCtx();
ZSTD_compressionParameters params; ZSTD_compressionParameters params;
winnerInfo_t winners[NB_LEVELS_TRACKED]; winnerInfo_t winners[NB_LEVELS_TRACKED];
int i;
unsigned u; unsigned u;
const char* rfName = "grillResults.txt"; const char* rfName = "grillResults.txt";
FILE* f; FILE* const f = fopen(rfName, "w");
const size_t blockSize = g_blockSize ? g_blockSize : srcSize; const size_t blockSize = g_blockSize ? g_blockSize : srcSize;
if (g_singleRun) { if (g_singleRun) {
@ -653,8 +653,8 @@ static void BMK_benchMem(void* srcBuffer, size_t srcSize)
} }
/* init */ /* init */
if (ctx==NULL) { DISPLAY("ZSTD_createCCtx() failed \n"); exit(1); }
memset(winners, 0, sizeof(winners)); memset(winners, 0, sizeof(winners));
f = fopen(rfName, "w");
if (f==NULL) { DISPLAY("error opening %s \n", rfName); exit(1); } if (f==NULL) { DISPLAY("error opening %s \n", rfName); exit(1); }
if (g_target) if (g_target)
@ -672,18 +672,16 @@ static void BMK_benchMem(void* srcBuffer, size_t srcSize)
g_cSpeedTarget[u] = (g_cSpeedTarget[u-1] * 25) >> 5; g_cSpeedTarget[u] = (g_cSpeedTarget[u-1] * 25) >> 5;
/* populate initial solution */ /* populate initial solution */
{ { const int maxSeeds = g_noSeed ? 1 : ZSTD_maxCLevel();
const int maxSeeds = g_noSeed ? 1 : ZSTD_maxCLevel(); int i;
for (i=1; i<=maxSeeds; i++) { for (i=0; i<=maxSeeds; i++) {
params = ZSTD_getCParams(i, blockSize, 0); params = ZSTD_getCParams(i, blockSize, 0);
BMK_seed(winners, params, srcBuffer, srcSize, ctx); BMK_seed(winners, params, srcBuffer, srcSize, ctx);
} } }
}
BMK_printWinners(f, winners, srcSize); BMK_printWinners(f, winners, srcSize);
/* start tests */ /* start tests */
{ { const int milliStart = BMK_GetMilliStart();
const int milliStart = BMK_GetMilliStart();
do { do {
BMK_selectRandomStart(f, winners, srcBuffer, srcSize, ctx); BMK_selectRandomStart(f, winners, srcBuffer, srcSize, ctx);
} while (BMK_GetMilliSpan(milliStart) < g_grillDuration); } while (BMK_GetMilliSpan(milliStart) < g_grillDuration);
@ -702,8 +700,8 @@ static void BMK_benchMem(void* srcBuffer, size_t srcSize)
static int benchSample(void) static int benchSample(void)
{ {
void* origBuff; void* origBuff;
size_t benchedSize = sampleSize; size_t const benchedSize = sampleSize;
const char* name = "Sample 10MiB"; const char* const name = "Sample 10MiB";
/* Allocation */ /* Allocation */
origBuff = malloc(benchedSize); origBuff = malloc(benchedSize);
@ -722,37 +720,31 @@ static int benchSample(void)
} }
int benchFiles(char** fileNamesTable, int nbFiles) int benchFiles(const char** fileNamesTable, int nbFiles)
{ {
int fileIdx=0; int fileIdx=0;
/* Loop for each file */ /* Loop for each file */
while (fileIdx<nbFiles) { while (fileIdx<nbFiles) {
FILE* inFile; const char* const inFileName = fileNamesTable[fileIdx++];
char* inFileName; FILE* const inFile = fopen( inFileName, "rb" );
U64 inFileSize; U64 const inFileSize = UTIL_getFileSize(inFileName);
size_t benchedSize; size_t benchedSize;
size_t readSize; void* origBuff;
char* origBuff;
/* Check file existence */ /* Check file existence */
inFileName = fileNamesTable[fileIdx++];
inFile = fopen( inFileName, "rb" );
if (inFile==NULL) { if (inFile==NULL) {
DISPLAY( "Pb opening %s\n", inFileName); DISPLAY( "Pb opening %s\n", inFileName);
return 11; return 11;
} }
/* Memory allocation & restrictions */ /* Memory allocation */
inFileSize = UTIL_getFileSize(inFileName);
benchedSize = BMK_findMaxMem(inFileSize*3) / 3; benchedSize = BMK_findMaxMem(inFileSize*3) / 3;
if ((U64)benchedSize > inFileSize) benchedSize = (size_t)inFileSize; if ((U64)benchedSize > inFileSize) benchedSize = (size_t)inFileSize;
if (benchedSize < inFileSize) if (benchedSize < inFileSize)
DISPLAY("Not enough memory for '%s' full size; testing %i MB only...\n", inFileName, (int)(benchedSize>>20)); DISPLAY("Not enough memory for '%s' full size; testing %i MB only...\n", inFileName, (int)(benchedSize>>20));
origBuff = malloc(benchedSize);
/* Alloc */ if (origBuff==NULL) {
origBuff = (char*) malloc((size_t)benchedSize);
if(!origBuff) {
DISPLAY("\nError: not enough memory!\n"); DISPLAY("\nError: not enough memory!\n");
fclose(inFile); fclose(inFile);
return 12; return 12;
@ -760,26 +752,28 @@ int benchFiles(char** fileNamesTable, int nbFiles)
/* Fill input buffer */ /* Fill input buffer */
DISPLAY("Loading %s... \r", inFileName); DISPLAY("Loading %s... \r", inFileName);
readSize = fread(origBuff, 1, benchedSize, inFile); { size_t const readSize = fread(origBuff, 1, benchedSize, inFile);
fclose(inFile); fclose(inFile);
if(readSize != benchedSize) {
if(readSize != benchedSize) { DISPLAY("\nError: problem reading file '%s' !! \n", inFileName);
DISPLAY("\nError: problem reading file '%s' !! \n", inFileName); free(origBuff);
free(origBuff); return 13;
return 13; } }
}
/* bench */ /* bench */
DISPLAY("\r%79s\r", ""); DISPLAY("\r%79s\r", "");
DISPLAY("using %s : \n", inFileName); DISPLAY("using %s : \n", inFileName);
BMK_benchMem(origBuff, benchedSize); BMK_benchMem(origBuff, benchedSize);
/* clean */
free(origBuff);
} }
return 0; return 0;
} }
int optimizeForSize(char* inFileName) int optimizeForSize(const char* inFileName)
{ {
FILE* inFile; FILE* inFile;
U64 inFileSize; U64 inFileSize;
@ -824,8 +818,7 @@ int optimizeForSize(char* inFileName)
DISPLAY("\r%79s\r", ""); DISPLAY("\r%79s\r", "");
DISPLAY("optimizing for %s : \n", inFileName); DISPLAY("optimizing for %s : \n", inFileName);
{ { ZSTD_CCtx* ctx = ZSTD_createCCtx();
ZSTD_CCtx* ctx = ZSTD_createCCtx();
ZSTD_compressionParameters params; ZSTD_compressionParameters params;
winnerInfo_t winner; winnerInfo_t winner;
BMK_result_t candidate; BMK_result_t candidate;
@ -837,8 +830,7 @@ int optimizeForSize(char* inFileName)
winner.result.cSize = (size_t)(-1); winner.result.cSize = (size_t)(-1);
/* find best solution from default params */ /* find best solution from default params */
{ { const int maxSeeds = g_noSeed ? 1 : ZSTD_maxCLevel();
const int maxSeeds = g_noSeed ? 1 : ZSTD_maxCLevel();
for (i=1; i<=maxSeeds; i++) { for (i=1; i<=maxSeeds; i++) {
params = ZSTD_getCParams(i, blockSize, 0); params = ZSTD_getCParams(i, blockSize, 0);
BMK_benchParam(&candidate, origBuff, benchedSize, ctx, params); BMK_benchParam(&candidate, origBuff, benchedSize, ctx, params);
@ -853,8 +845,7 @@ int optimizeForSize(char* inFileName)
BMK_printWinner(stdout, 99, winner.result, winner.params, benchedSize); BMK_printWinner(stdout, 99, winner.result, winner.params, benchedSize);
/* start tests */ /* start tests */
{ { const int milliStart = BMK_GetMilliStart();
const int milliStart = BMK_GetMilliStart();
do { do {
params = winner.params; params = winner.params;
paramVariation(&params); paramVariation(&params);
@ -889,7 +880,7 @@ int optimizeForSize(char* inFileName)
} }
static int usage(char* exename) static int usage(const char* exename)
{ {
DISPLAY( "Usage :\n"); DISPLAY( "Usage :\n");
DISPLAY( " %s [arg] file\n", exename); DISPLAY( " %s [arg] file\n", exename);
@ -902,27 +893,28 @@ static int usage(char* exename)
static int usage_advanced(void) static int usage_advanced(void)
{ {
DISPLAY( "\nAdvanced options :\n"); DISPLAY( "\nAdvanced options :\n");
DISPLAY( " -i# : iteration loops [1-9](default : %i)\n", NBLOOPS); DISPLAY( " -T# : set level 1 speed objective \n");
DISPLAY( " -B# : cut input into blocks of size # (default : single block)\n"); DISPLAY( " -B# : cut input into blocks of size # (default : single block) \n");
DISPLAY( " -P# : generated sample compressibility (default : %.1f%%)\n", COMPRESSIBILITY_DEFAULT * 100); DISPLAY( " -i# : iteration loops [1-9](default : %i) \n", NBLOOPS);
DISPLAY( " -S : Single run\n"); DISPLAY( " -S : Single run \n");
DISPLAY( " -P# : generated sample compressibility (default : %.1f%%) \n", COMPRESSIBILITY_DEFAULT * 100);
return 0; return 0;
} }
static int badusage(char* exename) static int badusage(const char* exename)
{ {
DISPLAY("Wrong parameters\n"); DISPLAY("Wrong parameters\n");
usage(exename); usage(exename);
return 1; return 1;
} }
int main(int argc, char** argv) int main(int argc, const char** argv)
{ {
int i, int i,
filenamesStart=0, filenamesStart=0,
result; result;
char* exename=argv[0]; const char* exename=argv[0];
char* input_filename=0; const char* input_filename=0;
U32 optimizer = 0; U32 optimizer = 0;
U32 main_pause = 0; U32 main_pause = 0;
@ -938,7 +930,7 @@ int main(int argc, char** argv)
if (argc<1) { badusage(exename); return 1; } if (argc<1) { badusage(exename); return 1; }
for(i=1; i<argc; i++) { for(i=1; i<argc; i++) {
char* argument = argv[i]; const char* argument = argv[i];
if(!argument) continue; /* Protection if argument empty */ if(!argument) continue; /* Protection if argument empty */