-r# : test all compression levels from -bX to #

This commit is contained in:
inikep 2016-03-14 18:10:30 +01:00
parent 44af12deb1
commit e9554b73cc
3 changed files with 51 additions and 48 deletions

View File

@ -419,49 +419,46 @@ static size_t BMK_findMaxMem(U64 requiredMem)
} }
static void BMK_benchCLevel(void* srcBuffer, size_t benchedSize, static void BMK_benchCLevel(void* srcBuffer, size_t benchedSize,
const char* displayName, int cLevel, const char* displayName, int cLevel, int cLevelLast,
const size_t* fileSizes, unsigned nbFiles, const size_t* fileSizes, unsigned nbFiles,
const void* dictBuffer, size_t dictBufferSize) const void* dictBuffer, size_t dictBufferSize)
{ {
benchResult_t result, total; benchResult_t result, total;
int l;
if (cLevel < 0) { const char* pch = strrchr(displayName, '\\'); /* Windows */
int l; if (!pch) pch = strrchr(displayName, '/'); /* Linux */
memset(&total, 0, sizeof(total)); if (pch) displayName = pch+1;
const char* pch = strrchr(displayName, '\\'); /* Windows */
if (!pch) pch = strrchr(displayName, '/'); /* Linux */
if (pch) displayName = pch+1;
if (g_displayLevel == 1) memset(&result, 0, sizeof(result));
DISPLAY("bench %s: input %u bytes, %i iterations, %u KB blocks\n", ZSTD_VERSION, (U32)benchedSize, nbIterations, (U32)(g_blockSize>>10)); memset(&total, 0, sizeof(total));
for (l=1; l <= -cLevel; l++) { if (g_displayLevel == 1)
BMK_benchMem(srcBuffer, benchedSize, DISPLAY("bench %s: input %u bytes, %i iterations, %u KB blocks\n", ZSTD_VERSION, (U32)benchedSize, nbIterations, (U32)(g_blockSize>>10));
displayName, l,
fileSizes, nbFiles, if (cLevelLast < cLevel) cLevelLast = cLevel;
dictBuffer, dictBufferSize, &result);
if (g_displayLevel == 1) { for (l=cLevel; l <= cLevelLast; l++) {
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); BMK_benchMem(srcBuffer, benchedSize,
total.cSize += result.cSize; displayName, l,
total.cSpeed += result.cSpeed; fileSizes, nbFiles,
total.dSpeed += result.dSpeed; dictBuffer, dictBufferSize, &result);
total.ratio += result.ratio; if (g_displayLevel == 1) {
} 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;
total.cSpeed += result.cSpeed;
total.dSpeed += result.dSpeed;
total.ratio += result.ratio;
} }
if (g_displayLevel == 1)
{
total.cSize /= -cLevel;
total.cSpeed /= -cLevel;
total.dSpeed /= -cLevel;
total.ratio /= -cLevel;
DISPLAY("avg%11i (%5.3f) %6.1f MB/s %6.1f MB/s %s\n", (int)total.cSize, total.ratio, total.cSpeed, total.dSpeed, displayName);
}
return;
} }
BMK_benchMem(srcBuffer, benchedSize, if (g_displayLevel == 1 && cLevelLast > cLevel)
displayName, cLevel, {
fileSizes, nbFiles, total.cSize /= 1+cLevelLast-cLevel;
dictBuffer, dictBufferSize, &result); total.cSpeed /= 1+cLevelLast-cLevel;
total.dSpeed /= 1+cLevelLast-cLevel;
total.ratio /= 1+cLevelLast-cLevel;
DISPLAY("avg%11i (%5.3f) %6.1f MB/s %6.1f MB/s %s\n", (int)total.cSize, total.ratio, total.cSpeed, total.dSpeed, displayName);
}
} }
static U64 BMK_getTotalFileSize(const char** fileNamesTable, unsigned nbFiles) static U64 BMK_getTotalFileSize(const char** fileNamesTable, unsigned nbFiles)
@ -497,7 +494,7 @@ static void BMK_loadFiles(void* buffer, size_t bufferSize,
} }
static void BMK_benchFileTable(const char** fileNamesTable, unsigned nbFiles, static void BMK_benchFileTable(const char** fileNamesTable, unsigned nbFiles,
const char* dictFileName, int cLevel) const char* dictFileName, int cLevel, int cLevelLast)
{ {
void* srcBuffer; void* srcBuffer;
size_t benchedSize; size_t benchedSize;
@ -537,7 +534,7 @@ static void BMK_benchFileTable(const char** fileNamesTable, unsigned nbFiles,
else displayName = fileNamesTable[0]; else displayName = fileNamesTable[0];
BMK_benchCLevel(srcBuffer, benchedSize, BMK_benchCLevel(srcBuffer, benchedSize,
displayName, cLevel, displayName, cLevel, cLevelLast,
fileSizes, nbFiles, fileSizes, nbFiles,
dictBuffer, dictBufferSize); dictBuffer, dictBufferSize);
@ -548,7 +545,7 @@ static void BMK_benchFileTable(const char** fileNamesTable, unsigned nbFiles,
} }
static void BMK_syntheticTest(int cLevel, double compressibility) static void BMK_syntheticTest(int cLevel, int cLevelLast, double compressibility)
{ {
char name[20] = {0}; char name[20] = {0};
size_t benchedSize = 10000000; size_t benchedSize = 10000000;
@ -562,7 +559,7 @@ static void BMK_syntheticTest(int cLevel, double compressibility)
/* Bench */ /* Bench */
snprintf (name, sizeof(name), "Synthetic %2u%%", (unsigned)(compressibility*100)); snprintf (name, sizeof(name), "Synthetic %2u%%", (unsigned)(compressibility*100));
BMK_benchCLevel(srcBuffer, benchedSize, name, cLevel, &benchedSize, 1, NULL, 0); BMK_benchCLevel(srcBuffer, benchedSize, name, cLevel, cLevelLast, &benchedSize, 1, NULL, 0);
/* clean up */ /* clean up */
free(srcBuffer); free(srcBuffer);
@ -570,14 +567,14 @@ static void BMK_syntheticTest(int cLevel, double compressibility)
int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles, int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles,
const char* dictFileName, int cLevel) const char* dictFileName, int cLevel, int cLevelLast)
{ {
double compressibility = (double)g_compressibilityDefault / 100; double compressibility = (double)g_compressibilityDefault / 100;
if (nbFiles == 0) if (nbFiles == 0)
BMK_syntheticTest(cLevel, compressibility); BMK_syntheticTest(cLevel, cLevelLast, compressibility);
else else
BMK_benchFileTable(fileNamesTable, nbFiles, dictFileName, cLevel); BMK_benchFileTable(fileNamesTable, nbFiles, dictFileName, cLevel, cLevelLast);
return 0; return 0;
} }

View File

@ -27,7 +27,7 @@
/* Main function */ /* Main function */
int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles, int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles,
const char* dictFileName, int cLevel); const char* dictFileName, int cLevel, int cLevelLast);
/* Set Parameters */ /* Set Parameters */
void BMK_SetNbIterations(int nbLoops); void BMK_SetNbIterations(int nbLoops);

View File

@ -142,9 +142,9 @@ static int usage_advanced(const char* programName)
#ifndef ZSTD_NOBENCH #ifndef ZSTD_NOBENCH
DISPLAY( "Benchmark arguments :\n"); DISPLAY( "Benchmark arguments :\n");
DISPLAY( " -b# : benchmark file(s), using # compression level (default : 1) \n"); DISPLAY( " -b# : benchmark file(s), using # compression level (default : 1) \n");
DISPLAY( " -r# : test all compression levels from -bX to # (default: 1)\n");
DISPLAY( " -i# : iteration loops [1-9](default : 3)\n"); DISPLAY( " -i# : iteration loops [1-9](default : 3)\n");
DISPLAY( " -B# : cut file into independent blocks of size # (default: no block)\n"); DISPLAY( " -B# : cut file into independent blocks of size # (default: no block)\n");
DISPLAY( " -r# : test all compression levels from 1 to # (default: disabled)\n");
#endif #endif
return 0; return 0;
} }
@ -179,19 +179,19 @@ int main(int argCount, const char** argv)
nextArgumentIsOutFileName=0, nextArgumentIsOutFileName=0,
nextArgumentIsMaxDict=0; nextArgumentIsMaxDict=0;
unsigned cLevel = 1; unsigned cLevel = 1;
unsigned cLevelLast = 1;
const char** filenameTable = (const char**)malloc(argCount * sizeof(const char*)); /* argCount >= 1 */ const char** filenameTable = (const char**)malloc(argCount * sizeof(const char*)); /* argCount >= 1 */
unsigned filenameIdx = 0; unsigned filenameIdx = 0;
const char* programName = argv[0]; const char* programName = argv[0];
const char* outFileName = NULL; const char* outFileName = NULL;
const char* dictFileName = NULL; const char* dictFileName = NULL;
char* dynNameSpace = NULL; char* dynNameSpace = NULL;
int rangeBench = 1;
unsigned maxDictSize = g_defaultMaxDictSize; unsigned maxDictSize = g_defaultMaxDictSize;
unsigned dictCLevel = g_defaultDictCLevel; unsigned dictCLevel = g_defaultDictCLevel;
unsigned dictSelect = g_defaultSelectivityLevel; unsigned dictSelect = g_defaultSelectivityLevel;
/* init */ /* init */
(void)rangeBench; (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); } if (filenameTable==NULL) { DISPLAY("not enough memory\n"); exit(1); }
displayOut = stderr; displayOut = stderr;
/* Pick out program name from path. Don't rely on stdlib because of conflicting behavior */ /* Pick out program name from path. Don't rely on stdlib because of conflicting behavior */
@ -313,8 +313,14 @@ int main(int argCount, const char** argv)
/* range bench (benchmark only) */ /* range bench (benchmark only) */
case 'r': case 'r':
rangeBench = -1; /* compression Level */
argument++; argument++;
if ((*argument>='0') && (*argument<='9')) {
cLevelLast = 0;
while ((*argument >= '0') && (*argument <= '9'))
cLevelLast *= 10, cLevelLast += *argument++ - '0';
continue;
}
break; break;
#endif /* ZSTD_NOBENCH */ #endif /* ZSTD_NOBENCH */
@ -369,7 +375,7 @@ int main(int argCount, const char** argv)
if (bench) { if (bench) {
#ifndef ZSTD_NOBENCH #ifndef ZSTD_NOBENCH
BMK_setNotificationLevel(displayLevel); BMK_setNotificationLevel(displayLevel);
BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel*rangeBench); BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel, cLevelLast);
#endif #endif
goto _end; goto _end;
} }