From: George Lu Date: Fri, 27 Jul 2018 15:20:31 +0000 (-0700) Subject: Generalize, macro magic numbers X-Git-Tag: v0.0.29~43^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ff0de15e4484b656dc199e118b063b3665cb2dd;p=thirdparty%2Fzstd.git Generalize, macro magic numbers --- diff --git a/tests/README.md b/tests/README.md index 2f0026fda..04eb5094e 100644 --- a/tests/README.md +++ b/tests/README.md @@ -112,6 +112,9 @@ Full list of arguments dSpeed= - Minimum decompression speed cMem= - compression memory lvl= - Automatically sets compression speed constraint to the speed of that level + stc= - In lvl mode, represents slack in ratio/cSpeed allowed for a solution to be considered + - In normal operation, represents slack in strategy selection in choosing the default parameters + --optimize= : same as -O with more verbose syntax -P# : generated sample compressibility -t# : Caps runtime of operation in seconds (default : 99999 seconds (about 27 hours )) -v : Prints Benchmarking output diff --git a/tests/paramgrill.c b/tests/paramgrill.c index 0db8510e1..fca6b2002 100644 --- a/tests/paramgrill.c +++ b/tests/paramgrill.c @@ -139,8 +139,9 @@ struct ll_node { static ll_node* g_winners; /* linked list sorted ascending by cSize & cSpeed */ static BMK_result_t g_lvltarget; -/* range 0 - 99 */ -static U32 g_strictness = 99; +/* range 0 - 99, measure of how strict */ +#define DEFAULT_STRICTNESS 99999 +static U32 g_strictness = DEFAULT_STRICTNESS; void BMK_SetNbIterations(int nbLoops) { @@ -318,8 +319,8 @@ static int compareResultLT(const BMK_result_t result1, const BMK_result_t result static constraint_t relaxTarget(constraint_t target) { target.cMem = (U32)-1; - target.cSpeed *= ((double)(g_strictness + 1) / 100); - target.dSpeed *= ((double)(g_strictness + 1) / 100); + target.cSpeed *= ((double)(g_strictness) / 100); + target.dSpeed *= ((double)(g_strictness) / 100); return target; } @@ -2080,8 +2081,7 @@ static ZSTD_compressionParameters maskParams(ZSTD_compressionParameters base, ZS } /* experiment with playing with this and decay value */ -#define MAX_TRIES 8 -#define TRY_DECAY 3 + /* main fn called when using --optimize */ /* Does strategy selection by benchmarking default compression levels * then optimizes by strategy, starting with the best one and moving @@ -2095,6 +2095,9 @@ static ZSTD_compressionParameters maskParams(ZSTD_compressionParameters base, ZS * cLevel - compression level to exceed (all solutions must be > lvl in cSpeed + ratio) */ +#define MAX_TRIES 3 +#define TRY_DECAY 1 + static int optimizeForSize(const char* const * const fileNamesTable, const size_t nbFiles, const char* dictFileName, constraint_t target, ZSTD_compressionParameters paramTarget, int cLevel) { varInds_t varArray [NUM_PARAMS]; @@ -2164,6 +2167,21 @@ static int optimizeForSize(const char* const * const fileNamesTable, const size_ goto _cleanUp; } + /* default strictness = Maximum for */ + if(g_strictness == DEFAULT_STRICTNESS) { + if(cLevel) { + g_strictness = 99; + } else { + g_strictness = 90; + } + } else { + if(0 >= g_strictness || g_strictness > 100) { + DISPLAY("Strictness Outside of Bounds\n"); + ret = 4; + goto _cleanUp; + } + } + /* use level'ing mode instead of normal target mode */ if(cLevel) { winner.params = ZSTD_getCParams(cLevel, maxBlockSize, ctx.dictSize); @@ -2177,8 +2195,8 @@ static int optimizeForSize(const char* const * const fileNamesTable, const size_ g_targetConstraints = target; g_lvltarget = winner.result; - g_lvltarget.cSpeed *= ((double)(g_strictness + 1) / 100); - g_lvltarget.cSize /= ((double)(g_strictness + 1) / 100); + g_lvltarget.cSpeed *= ((double)(g_strictness) / 100); + g_lvltarget.cSize /= ((double)(g_strictness) / 100); BMK_printWinnerOpt(stdout, cLevel, winner.result, winner.params, target, buf.srcSize); } @@ -2199,6 +2217,7 @@ static int optimizeForSize(const char* const * const fileNamesTable, const size_ { varInds_t varNew[NUM_PARAMS]; + ZSTD_compressionParameters CParams; /* find best solution from default params */ { @@ -2210,8 +2229,7 @@ static int optimizeForSize(const char* const * const fileNamesTable, const size_ int i; for (i=1; i<=maxSeeds; i++) { int ec; - ZSTD_compressionParameters CParams = ZSTD_getCParams(i, maxBlockSize, ctx.dictSize); - CParams = maskParams(CParams, paramTarget); + CParams = maskParams(ZSTD_getCParams(i, maxBlockSize, ctx.dictSize), paramTarget); ec = BMK_benchParam(&candidate, buf, ctx, CParams); BMK_printWinnerOpt(stdout, i, candidate, CParams, target, buf.srcSize); @@ -2221,9 +2239,7 @@ static int optimizeForSize(const char* const * const fileNamesTable, const size_ } /* if the current params are too slow, just stop. */ - if(target.cSpeed != 0 && target.cSpeed > winner.result.cSpeed / 2) { - break; - } + if(target.cSpeed > candidate.cSpeed * 2) { break; } } } } @@ -2239,6 +2255,7 @@ static int optimizeForSize(const char* const * const fileNamesTable, const size_ int tries = MAX_TRIES; { + /* one iterations of hill climbing with the level-defined parameters. */ int varLenNew = sanitizeVarArray(varNew, varLen, varArray, st); winnerInfo_t w1 = climbOnce(target, varNew, varLenNew, allMT[st], buf, ctx, winner.params); @@ -2247,16 +2264,19 @@ static int optimizeForSize(const char* const * const fileNamesTable, const size_ } } - while(st && tries) { + while(st && tries > 0) { DEBUGOUTPUT("StrategySwitch: %s\n", g_stratName[st]); winnerInfo_t wc = optimizeFixedStrategy(buf, ctx, target, paramTarget, st, varArray, varLen, allMT[st], tries); + if(compareResultLT(winner.result, wc.result, target, buf.srcSize)) { winner = wc; + tries = MAX_TRIES; + bestStrategy = st; + } else { + st = nextStrategy(st, bestStrategy); + tries -= TRY_DECAY; } - - st = nextStrategy(st, bestStrategy); - tries -= TRY_DECAY; } } else { winner = optimizeFixedStrategy(buf, ctx, target, paramTarget, paramTarget.strategy,