From a43a854cdbb08dd72dee12785023a6c5e3a459f9 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 12 Jul 2016 13:42:10 +0200 Subject: [PATCH] updated paramgrill --- lib/compress/zstd_compress.c | 10 ++-- programs/paramgrill.c | 96 +++++++++++++++++------------------- 2 files changed, 49 insertions(+), 57 deletions(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 70f17b53..08157c1e 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -2939,7 +2939,7 @@ unsigned ZSTD_maxCLevel(void) { return ZSTD_MAX_CLEVEL; } static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEVEL+1] = { { /* "default" */ /* 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, 15, 16, 1, 6, 4, ZSTD_fast }, /* level 2 */ { 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 */ /* 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, 15, 17, 1, 5, 4, ZSTD_fast }, /* level 2 */ { 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 */ /* 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, 13, 16, 1, 5, 4, ZSTD_fast }, /* level 2 */ { 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 */ /* 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, 15, 1, 4, 4, ZSTD_fast }, /* level 2 */ { 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() : -* 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) */ ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSize, size_t dictSize) { ZSTD_parameters params; diff --git a/programs/paramgrill.c b/programs/paramgrill.c index 3078748f..ffa0b3e0 100644 --- a/programs/paramgrill.c +++ b/programs/paramgrill.c @@ -363,6 +363,7 @@ static size_t BMK_benchParam(BMK_result_t* resultPtr, const char* g_stratName[] = { "ZSTD_fast ", + "ZSTD_dfast ", "ZSTD_greedy ", "ZSTD_lazy ", "ZSTD_lazy2 ", @@ -635,13 +636,12 @@ static void BMK_selectRandomStart( static void BMK_benchMem(void* srcBuffer, size_t srcSize) { - ZSTD_CCtx* ctx = ZSTD_createCCtx(); + ZSTD_CCtx* const ctx = ZSTD_createCCtx(); ZSTD_compressionParameters params; winnerInfo_t winners[NB_LEVELS_TRACKED]; - int i; unsigned u; const char* rfName = "grillResults.txt"; - FILE* f; + FILE* const f = fopen(rfName, "w"); const size_t blockSize = g_blockSize ? g_blockSize : srcSize; if (g_singleRun) { @@ -653,8 +653,8 @@ static void BMK_benchMem(void* srcBuffer, size_t srcSize) } /* init */ + if (ctx==NULL) { DISPLAY("ZSTD_createCCtx() failed \n"); exit(1); } memset(winners, 0, sizeof(winners)); - f = fopen(rfName, "w"); if (f==NULL) { DISPLAY("error opening %s \n", rfName); exit(1); } 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; /* populate initial solution */ - { - const int maxSeeds = g_noSeed ? 1 : ZSTD_maxCLevel(); - for (i=1; i<=maxSeeds; i++) { + { const int maxSeeds = g_noSeed ? 1 : ZSTD_maxCLevel(); + int i; + for (i=0; i<=maxSeeds; i++) { params = ZSTD_getCParams(i, blockSize, 0); BMK_seed(winners, params, srcBuffer, srcSize, ctx); - } - } + } } BMK_printWinners(f, winners, srcSize); /* start tests */ - { - const int milliStart = BMK_GetMilliStart(); + { const int milliStart = BMK_GetMilliStart(); do { BMK_selectRandomStart(f, winners, srcBuffer, srcSize, ctx); } while (BMK_GetMilliSpan(milliStart) < g_grillDuration); @@ -702,8 +700,8 @@ static void BMK_benchMem(void* srcBuffer, size_t srcSize) static int benchSample(void) { void* origBuff; - size_t benchedSize = sampleSize; - const char* name = "Sample 10MiB"; + size_t const benchedSize = sampleSize; + const char* const name = "Sample 10MiB"; /* Allocation */ 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; /* Loop for each file */ while (fileIdx inFileSize) benchedSize = (size_t)inFileSize; if (benchedSize < inFileSize) DISPLAY("Not enough memory for '%s' full size; testing %i MB only...\n", inFileName, (int)(benchedSize>>20)); - - /* Alloc */ - origBuff = (char*) malloc((size_t)benchedSize); - if(!origBuff) { + origBuff = malloc(benchedSize); + if (origBuff==NULL) { DISPLAY("\nError: not enough memory!\n"); fclose(inFile); return 12; @@ -760,26 +752,28 @@ int benchFiles(char** fileNamesTable, int nbFiles) /* Fill input buffer */ DISPLAY("Loading %s... \r", inFileName); - readSize = fread(origBuff, 1, benchedSize, inFile); - fclose(inFile); - - if(readSize != benchedSize) { - DISPLAY("\nError: problem reading file '%s' !! \n", inFileName); - free(origBuff); - return 13; - } + { size_t const readSize = fread(origBuff, 1, benchedSize, inFile); + fclose(inFile); + if(readSize != benchedSize) { + DISPLAY("\nError: problem reading file '%s' !! \n", inFileName); + free(origBuff); + return 13; + } } /* bench */ DISPLAY("\r%79s\r", ""); DISPLAY("using %s : \n", inFileName); BMK_benchMem(origBuff, benchedSize); + + /* clean */ + free(origBuff); } return 0; } -int optimizeForSize(char* inFileName) +int optimizeForSize(const char* inFileName) { FILE* inFile; U64 inFileSize; @@ -824,8 +818,7 @@ int optimizeForSize(char* inFileName) DISPLAY("\r%79s\r", ""); DISPLAY("optimizing for %s : \n", inFileName); - { - ZSTD_CCtx* ctx = ZSTD_createCCtx(); + { ZSTD_CCtx* ctx = ZSTD_createCCtx(); ZSTD_compressionParameters params; winnerInfo_t winner; BMK_result_t candidate; @@ -837,8 +830,7 @@ int optimizeForSize(char* inFileName) winner.result.cSize = (size_t)(-1); /* 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++) { params = ZSTD_getCParams(i, blockSize, 0); BMK_benchParam(&candidate, origBuff, benchedSize, ctx, params); @@ -853,8 +845,7 @@ int optimizeForSize(char* inFileName) BMK_printWinner(stdout, 99, winner.result, winner.params, benchedSize); /* start tests */ - { - const int milliStart = BMK_GetMilliStart(); + { const int milliStart = BMK_GetMilliStart(); do { params = winner.params; paramVariation(¶ms); @@ -889,7 +880,7 @@ int optimizeForSize(char* inFileName) } -static int usage(char* exename) +static int usage(const char* exename) { DISPLAY( "Usage :\n"); DISPLAY( " %s [arg] file\n", exename); @@ -902,27 +893,28 @@ static int usage(char* exename) static int usage_advanced(void) { DISPLAY( "\nAdvanced options :\n"); - DISPLAY( " -i# : iteration loops [1-9](default : %i)\n", NBLOOPS); - DISPLAY( " -B# : cut input into blocks of size # (default : single block)\n"); - DISPLAY( " -P# : generated sample compressibility (default : %.1f%%)\n", COMPRESSIBILITY_DEFAULT * 100); - DISPLAY( " -S : Single run\n"); + DISPLAY( " -T# : set level 1 speed objective \n"); + DISPLAY( " -B# : cut input into blocks of size # (default : single block) \n"); + DISPLAY( " -i# : iteration loops [1-9](default : %i) \n", NBLOOPS); + DISPLAY( " -S : Single run \n"); + DISPLAY( " -P# : generated sample compressibility (default : %.1f%%) \n", COMPRESSIBILITY_DEFAULT * 100); return 0; } -static int badusage(char* exename) +static int badusage(const char* exename) { DISPLAY("Wrong parameters\n"); usage(exename); return 1; } -int main(int argc, char** argv) +int main(int argc, const char** argv) { int i, filenamesStart=0, result; - char* exename=argv[0]; - char* input_filename=0; + const char* exename=argv[0]; + const char* input_filename=0; U32 optimizer = 0; U32 main_pause = 0; @@ -938,7 +930,7 @@ int main(int argc, char** argv) if (argc<1) { badusage(exename); return 1; } for(i=1; i