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)
{
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;
}
}
/* 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
* 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];
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);
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);
}
{
varInds_t varNew[NUM_PARAMS];
+ ZSTD_compressionParameters CParams;
/* find best solution from default params */
{
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);
}
/* 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; }
}
}
}
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);
}
}
- 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,