update fullbench.c to work with new bench.h

This commit is contained in:
Yann Collet 2018-08-23 14:28:51 -07:00
parent 2e45badff4
commit d39a25c5ed
2 changed files with 117 additions and 111 deletions

View File

@ -311,7 +311,7 @@ BMK_runOutcome_t BMK_benchFunction(
size_t blockCount, size_t blockCount,
const void* const * srcBlockBuffers, const size_t* srcBlockSizes, const void* const * srcBlockBuffers, const size_t* srcBlockSizes,
void* const * dstBlockBuffers, const size_t* dstBlockCapacities, void* const * dstBlockBuffers, const size_t* dstBlockCapacities,
size_t* blockResult, size_t* blockResults,
unsigned nbLoops) unsigned nbLoops)
{ {
size_t dstSize = 0; size_t dstSize = 0;
@ -350,7 +350,7 @@ BMK_runOutcome_t BMK_benchFunction(
blockNb, (U32)dstBlockCapacities[blockNb], ZSTD_getErrorName(res)); blockNb, (U32)dstBlockCapacities[blockNb], ZSTD_getErrorName(res));
} else if (loopNb == 0) { } else if (loopNb == 0) {
dstSize += res; dstSize += res;
if (blockResult != NULL) blockResult[blockNb] = res; if (blockResults != NULL) blockResults[blockNb] = res;
dstSize += res; dstSize += res;
} } } }
} /* for (loopNb = 0; loopNb < nbLoops; loopNb++) */ } /* for (loopNb = 0; loopNb < nbLoops; loopNb++) */

View File

@ -333,14 +333,16 @@ size_t local_ZSTD_decompressContinue(const void* src, size_t srcSize, void* dst,
/*_******************************************************* /*_*******************************************************
* Bench functions * Bench functions
*********************************************************/ *********************************************************/
static size_t benchMem(const void* src, size_t srcSize, U32 benchNb, int cLevel, ZSTD_compressionParameters* cparams) static size_t benchMem(U32 benchNb,
const void* src, size_t srcSize,
int cLevel, ZSTD_compressionParameters cparams)
{ {
BYTE* dstBuff; BYTE* dstBuff;
size_t dstBuffSize = ZSTD_compressBound(srcSize); size_t dstBuffSize = ZSTD_compressBound(srcSize);
void* buff2, *buff1; void* buff1;
void* buff2;
const char* benchName; const char* benchName;
BMK_benchFn_t benchFunction; BMK_benchFn_t benchFunction;
BMK_customReturn_t r;
int errorcode = 0; int errorcode = 0;
/* Selection */ /* Selection */
@ -405,44 +407,44 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb, int cLevel,
if (g_cstream==NULL) g_cstream = ZSTD_createCStream(); if (g_cstream==NULL) g_cstream = ZSTD_createCStream();
if (g_dstream==NULL) g_dstream = ZSTD_createDStream(); if (g_dstream==NULL) g_dstream = ZSTD_createDStream();
/* DISPLAY("params: cLevel %d, wlog %d hlog %d clog %d slog %d slen %d tlen %d strat %d \n" /* DISPLAY("params: cLevel %d, wlog %d hlog %d clog %d slog %d slen %d tlen %d strat %d \n",
, cLevel, cparams->windowLog, cparams->hashLog, cparams->chainLog, cparams->searchLog, cLevel, cparams->windowLog, cparams->hashLog, cparams->chainLog, cparams->searchLog,
cparams->searchLength, cparams->targetLength, cparams->strategy);*/ cparams->searchLength, cparams->targetLength, cparams->strategy); */
ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_compressionLevel, cLevel); ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_compressionLevel, cLevel);
ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_windowLog, cparams->windowLog); ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_windowLog, cparams.windowLog);
ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_hashLog, cparams->hashLog); ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_hashLog, cparams.hashLog);
ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_chainLog, cparams->chainLog); ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_chainLog, cparams.chainLog);
ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_searchLog, cparams->searchLog); ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_searchLog, cparams.searchLog);
ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_minMatch, cparams->searchLength); ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_minMatch, cparams.searchLength);
ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_targetLength, cparams->targetLength); ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_targetLength, cparams.targetLength);
ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_compressionStrategy, cparams->strategy); ZSTD_CCtx_setParameter(g_zcc, ZSTD_p_compressionStrategy, cparams.strategy);
ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_compressionLevel, cLevel); ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_compressionLevel, cLevel);
ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_windowLog, cparams->windowLog); ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_windowLog, cparams.windowLog);
ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_hashLog, cparams->hashLog); ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_hashLog, cparams.hashLog);
ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_chainLog, cparams->chainLog); ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_chainLog, cparams.chainLog);
ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_searchLog, cparams->searchLog); ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_searchLog, cparams.searchLog);
ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_minMatch, cparams->searchLength); ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_minMatch, cparams.searchLength);
ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_targetLength, cparams->targetLength); ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_targetLength, cparams.targetLength);
ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_compressionStrategy, cparams->strategy); ZSTD_CCtx_setParameter(g_cstream, ZSTD_p_compressionStrategy, cparams.strategy);
/* Preparation */ /* Preparation */
switch(benchNb) switch(benchNb)
{ {
case 1: case 1:
buff2 = (void*)cparams; buff2 = &cparams;
break; break;
case 2: case 2:
g_cSize = ZSTD_compress(buff2, dstBuffSize, src, srcSize, cLevel); g_cSize = ZSTD_compress(buff2, dstBuffSize, src, srcSize, cLevel);
break; break;
#ifndef ZSTD_DLL_IMPORT #ifndef ZSTD_DLL_IMPORT
case 11: case 11:
buff2 = (void*)cparams; buff2 = &cparams;
break; break;
case 12: case 12:
buff2 = (void*)cparams; buff2 = &cparams;
break; break;
case 13 : case 13 :
g_cSize = ZSTD_compress(buff2, dstBuffSize, src, srcSize, cLevel); g_cSize = ZSTD_compress(buff2, dstBuffSize, src, srcSize, cLevel);
@ -495,7 +497,7 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb, int cLevel,
goto _cleanOut; goto _cleanOut;
#endif #endif
case 41 : case 41 :
buff2 = (void*)cparams; buff2 = &cparams;
break; break;
case 42 : case 42 :
g_cSize = ZSTD_compress(buff2, dstBuffSize, src, srcSize, cLevel); g_cSize = ZSTD_compress(buff2, dstBuffSize, src, srcSize, cLevel);
@ -507,25 +509,28 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb, int cLevel,
default : ; default : ;
} }
/* warming up dstBuff */
/* warming up memory */
{ size_t i; for (i=0; i<dstBuffSize; i++) dstBuff[i]=(BYTE)i; } { size_t i; for (i=0; i<dstBuffSize; i++) dstBuff[i]=(BYTE)i; }
/* benchmark loop */ /* benchmark loop */
{ { void* dstBuffv = dstBuff;
void* dstBuffv = (void*)dstBuff; BMK_runOutcome_t const outcome = BMK_benchFunction(
r = BMK_benchFunction(benchFunction, buff2, benchFunction, buff2,
NULL, NULL, 1, &src, &srcSize, NULL, NULL, /* initFn */
&dstBuffv, &dstBuffSize, NULL, g_nbIterations); 1, /* blockCount */
if(r.error) { &src, &srcSize,
DISPLAY("ERROR %d ! ! \n", r.error); &dstBuffv, &dstBuffSize,
errorcode = r.error; NULL,
g_nbIterations);
if (!BMK_isSuccessful_runOutcome(outcome)) {
DISPLAY("ERROR benchmarking function ! ! \n");
errorcode = 1;
goto _cleanOut; goto _cleanOut;
} }
DISPLAY("%2u#Speed: %f MB/s - Size: %f MB - %s\n", benchNb, (double)srcSize / r.result.nanoSecPerRun * 1000, (double)r.result.sumOfReturn / 1000000, benchName); { BMK_runTime_t const result = BMK_extract_runTime(outcome);
} DISPLAY("%2u#%-25.25s:%7.1f MB/s (%7u) \n", benchNb, benchName, (double)srcSize / result.nanoSecPerRun * 1000000000 / 1000000, (unsigned)result.sumOfReturn );
} }
_cleanOut: _cleanOut:
free(buff1); free(buff1);
@ -538,65 +543,70 @@ _cleanOut:
} }
static int benchSample(U32 benchNb, int cLevel, ZSTD_compressionParameters* cparams) static int benchSample(U32 benchNb,
int cLevel, ZSTD_compressionParameters cparams)
{ {
size_t const benchedSize = g_sampleSize; size_t const benchedSize = g_sampleSize;
const char* name = "Sample 10MiB"; const char* name = "Sample 10MiB";
/* Allocation */ /* Allocation */
void* origBuff = malloc(benchedSize); void* const origBuff = malloc(benchedSize);
if (!origBuff) { DISPLAY("\nError: not enough memory!\n"); return 12; } if (!origBuff) { DISPLAY("\nError: not enough memory!\n"); return 12; }
/* Fill buffer */ /* Fill buffer */
RDG_genBuffer(origBuff, benchedSize, g_compressibility, 0.0, 0); RDG_genBuffer(origBuff, benchedSize, g_compressibility, 0.0, 0);
/* bench */ /* bench */
DISPLAY("\r%79s\r", ""); DISPLAY("\r%70s\r", "");
DISPLAY(" %s : \n", name); DISPLAY(" %s : \n", name);
if (benchNb) if (benchNb) {
benchMem(origBuff, benchedSize, benchNb, cLevel, cparams); benchMem(benchNb, origBuff, benchedSize, cLevel, cparams);
else } else { /* 0 == run all tests */
for (benchNb=0; benchNb<100; benchNb++) benchMem(origBuff, benchedSize, benchNb, cLevel, cparams); for (benchNb=0; benchNb<100; benchNb++) {
benchMem(benchNb, origBuff, benchedSize, cLevel, cparams);
} }
free(origBuff); free(origBuff);
return 0; return 0;
} }
static int benchFiles(const char** fileNamesTable, const int nbFiles, U32 benchNb, int cLevel, ZSTD_compressionParameters* cparams) static int benchFiles(U32 benchNb,
const char** fileNamesTable, const int nbFiles,
int cLevel, ZSTD_compressionParameters cparams)
{ {
/* Loop for each file */ /* Loop for each file */
int fileIdx; int fileIdx;
for (fileIdx=0; fileIdx<nbFiles; fileIdx++) { for (fileIdx=0; fileIdx<nbFiles; fileIdx++) {
const char* const inFileName = fileNamesTable[fileIdx]; const char* const inFileName = fileNamesTable[fileIdx];
FILE* const inFile = fopen( inFileName, "rb" ); FILE* const inFile = fopen( inFileName, "rb" );
U64 inFileSize;
size_t benchedSize; size_t benchedSize;
void* origBuff;
/* Check file existence */ /* Check file existence */
if (inFile==NULL) { DISPLAY( "Pb opening %s\n", inFileName); return 11; } if (inFile==NULL) { DISPLAY( "Pb opening %s\n", inFileName); return 11; }
/* Memory allocation & restrictions */ /* Memory allocation & restrictions */
inFileSize = UTIL_getFileSize(inFileName); { U64 const inFileSize = UTIL_getFileSize(inFileName);
if (inFileSize == UTIL_FILESIZE_UNKNOWN) { if (inFileSize == UTIL_FILESIZE_UNKNOWN) {
DISPLAY( "Cannot measure size of %s\n", inFileName); DISPLAY( "Cannot measure size of %s\n", inFileName);
fclose(inFile); fclose(inFile);
return 11; return 11;
} }
benchedSize = BMK_findMaxMem(inFileSize*3) / 3; benchedSize = BMK_findMaxMem(inFileSize*3) / 3;
if ((U64)benchedSize > inFileSize) benchedSize = (size_t)inFileSize; if ((U64)benchedSize > inFileSize)
if (benchedSize < inFileSize) benchedSize = (size_t)inFileSize;
DISPLAY("Not enough memory for '%s' full size; testing %u MB only...\n", inFileName, (U32)(benchedSize>>20)); if ((U64)benchedSize < inFileSize) {
DISPLAY("Not enough memory for '%s' full size; testing %u MB only...\n",
inFileName, (U32)(benchedSize>>20));
} }
/* Alloc */ /* Alloc */
origBuff = malloc(benchedSize); { void* const origBuff = malloc(benchedSize);
if (!origBuff) { DISPLAY("\nError: not enough memory!\n"); fclose(inFile); return 12; } if (!origBuff) { DISPLAY("\nError: not enough memory!\n"); fclose(inFile); return 12; }
/* Fill input buffer */ /* Fill input buffer */
DISPLAY("Loading %s... \r", inFileName); DISPLAY("Loading %s... \r", inFileName);
{ { size_t const readSize = fread(origBuff, 1, benchedSize, inFile);
size_t 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);
@ -605,15 +615,17 @@ static int benchFiles(const char** fileNamesTable, const int nbFiles, U32 benchN
} } } }
/* bench */ /* bench */
DISPLAY("\r%79s\r", ""); DISPLAY("\r%70s\r", ""); /* blank line */
DISPLAY(" %s : \n", inFileName); DISPLAY(" %s : \n", inFileName);
if (benchNb) if (benchNb) {
benchMem(origBuff, benchedSize, benchNb, cLevel, cparams); benchMem(benchNb, origBuff, benchedSize, cLevel, cparams);
else } else {
for (benchNb=0; benchNb<100; benchNb++) benchMem(origBuff, benchedSize, benchNb, cLevel, cparams); for (benchNb=0; benchNb<100; benchNb++) {
benchMem(benchNb, origBuff, benchedSize, cLevel, cparams);
} }
free(origBuff); free(origBuff);
} } }
return 0; return 0;
} }
@ -649,7 +661,7 @@ static int badusage(const char* exename)
int main(int argc, const char** argv) int main(int argc, const char** argv)
{ {
int i, filenamesStart=0, result; int argNb, filenamesStart=0, result;
const char* exename = argv[0]; const char* exename = argv[0];
const char* input_filename = NULL; const char* input_filename = NULL;
U32 benchNb = 0, main_pause = 0; U32 benchNb = 0, main_pause = 0;
@ -659,8 +671,8 @@ int main(int argc, const char** argv)
DISPLAY(WELCOME_MESSAGE); DISPLAY(WELCOME_MESSAGE);
if (argc<1) return badusage(exename); if (argc<1) return badusage(exename);
for(i=1; i<argc; i++) { for(argNb=1; argNb<argc; argNb++) {
const char* argument = argv[i]; const char* argument = argv[argNb];
assert(argument != NULL); assert(argument != NULL);
if (longCommandWArg(&argument, "--zstd=")) { if (longCommandWArg(&argument, "--zstd=")) {
@ -677,12 +689,14 @@ int main(int argc, const char** argv)
return 1; return 1;
} }
/* check end of string */
if (argument[0] != 0) { if (argument[0] != 0) {
DISPLAY("invalid --zstd= format\n"); DISPLAY("invalid --zstd= format \n");
return 1; // check the end of string return 1;
} else { } else {
continue; continue;
} }
} else if (argument[0]=='-') { /* Commands (note : aggregated commands are allowed) */ } else if (argument[0]=='-') { /* Commands (note : aggregated commands are allowed) */
argument++; argument++;
while (argument[0]!=0) { while (argument[0]!=0) {
@ -698,35 +712,27 @@ int main(int argc, const char** argv)
/* Select specific algorithm to bench */ /* Select specific algorithm to bench */
case 'b': case 'b':
{
argument++; argument++;
benchNb = readU32FromChar(&argument); benchNb = readU32FromChar(&argument);
break; break;
}
/* Modify Nb Iterations */ /* Modify Nb Iterations */
case 'i': case 'i':
{
argument++; argument++;
BMK_SetNbIterations((int)readU32FromChar(&argument)); BMK_SetNbIterations((int)readU32FromChar(&argument));
}
break; break;
/* Select compressibility of synthetic sample */ /* Select compressibility of synthetic sample */
case 'P': case 'P':
{ argument++; argument++;
g_compressibility = (double)readU32FromChar(&argument) / 100.; g_compressibility = (double)readU32FromChar(&argument) / 100.;
}
break; break;
case 'l': case 'l':
{ argument++; argument++;
cLevel = readU32FromChar(&argument); cLevel = readU32FromChar(&argument);
cparams = ZSTD_getCParams(cLevel, 0, 0); cparams = ZSTD_getCParams(cLevel, 0, 0);
}
break; break;
/* Unknown command */ /* Unknown command */
default : return badusage(exename); default : return badusage(exename);
} }
@ -735,15 +741,15 @@ int main(int argc, const char** argv)
} }
/* first provided filename is input */ /* first provided filename is input */
if (!input_filename) { input_filename=argument; filenamesStart=i; continue; } if (!input_filename) { input_filename=argument; filenamesStart=argNb; continue; }
} }
if (filenamesStart==0) /* no input file */ if (filenamesStart==0) /* no input file */
result = benchSample(benchNb, cLevel, &cparams); result = benchSample(benchNb, cLevel, cparams);
else else
result = benchFiles(argv+filenamesStart, argc-filenamesStart, benchNb, cLevel, &cparams); result = benchFiles(benchNb, argv+filenamesStart, argc-filenamesStart, cLevel, cparams);
if (main_pause) { int unused; printf("press enter...\n"); unused = getchar(); (void)unused; } if (main_pause) { int unused; printf("press enter...\n"); unused = getchar(); (void)unused; }