diff --git a/programs/bench.c b/programs/bench.c index d95adb55..ba6a9ca8 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -311,7 +311,7 @@ BMK_runOutcome_t BMK_benchFunction( size_t blockCount, const void* const * srcBlockBuffers, const size_t* srcBlockSizes, void* const * dstBlockBuffers, const size_t* dstBlockCapacities, - size_t* blockResult, + size_t* blockResults, unsigned nbLoops) { size_t dstSize = 0; @@ -350,7 +350,7 @@ BMK_runOutcome_t BMK_benchFunction( blockNb, (U32)dstBlockCapacities[blockNb], ZSTD_getErrorName(res)); } else if (loopNb == 0) { dstSize += res; - if (blockResult != NULL) blockResult[blockNb] = res; + if (blockResults != NULL) blockResults[blockNb] = res; dstSize += res; } } } /* for (loopNb = 0; loopNb < nbLoops; loopNb++) */ diff --git a/tests/fullbench.c b/tests/fullbench.c index 12c1e1ae..2198f41d 100644 --- a/tests/fullbench.c +++ b/tests/fullbench.c @@ -290,7 +290,7 @@ size_t local_ZSTD_compressContinue(const void* src, size_t srcSize, void* dst, s size_t local_ZSTD_compressContinue_extDict(const void* src, size_t srcSize, void* dst, size_t dstCapacity, void* buff2) { BYTE firstBlockBuf[FIRST_BLOCK_SIZE]; - + ZSTD_parameters p; ZSTD_frameParameters f = {1 , 0, 0}; p.fParams = f; @@ -333,14 +333,16 @@ size_t local_ZSTD_decompressContinue(const void* src, size_t srcSize, void* dst, /*_******************************************************* * 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; size_t dstBuffSize = ZSTD_compressBound(srcSize); - void* buff2, *buff1; + void* buff1; + void* buff2; const char* benchName; BMK_benchFn_t benchFunction; - BMK_customReturn_t r; int errorcode = 0; /* 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_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" - , cLevel, cparams->windowLog, cparams->hashLog, cparams->chainLog, cparams->searchLog, - cparams->searchLength, cparams->targetLength, cparams->strategy);*/ + /* 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, + cparams->searchLength, cparams->targetLength, cparams->strategy); */ 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_hashLog, cparams->hashLog); - 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_minMatch, cparams->searchLength); - 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_windowLog, cparams.windowLog); + 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_searchLog, cparams.searchLog); + 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_compressionStrategy, cparams.strategy); 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_hashLog, cparams->hashLog); - 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_minMatch, cparams->searchLength); - 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_windowLog, cparams.windowLog); + 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_searchLog, cparams.searchLog); + 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_compressionStrategy, cparams.strategy); /* Preparation */ switch(benchNb) { case 1: - buff2 = (void*)cparams; + buff2 = &cparams; break; case 2: g_cSize = ZSTD_compress(buff2, dstBuffSize, src, srcSize, cLevel); break; #ifndef ZSTD_DLL_IMPORT case 11: - buff2 = (void*)cparams; + buff2 = &cparams; break; case 12: - buff2 = (void*)cparams; + buff2 = &cparams; break; case 13 : g_cSize = ZSTD_compress(buff2, dstBuffSize, src, srcSize, cLevel); @@ -494,8 +496,8 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb, int cLevel, case 31: goto _cleanOut; #endif - case 41 : - buff2 = (void*)cparams; + case 41 : + buff2 = &cparams; break; case 42 : g_cSize = ZSTD_compress(buff2, dstBuffSize, src, srcSize, cLevel); @@ -507,26 +509,29 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb, int cLevel, default : ; } - - /* warming up memory */ + /* warming up dstBuff */ { size_t i; for (i=0; i inFileSize) benchedSize = (size_t)inFileSize; - if (benchedSize < inFileSize) - DISPLAY("Not enough memory for '%s' full size; testing %u MB only...\n", inFileName, (U32)(benchedSize>>20)); - - /* Alloc */ - origBuff = malloc(benchedSize); - if (!origBuff) { DISPLAY("\nError: not enough memory!\n"); fclose(inFile); return 12; } - - /* Fill input buffer */ - DISPLAY("Loading %s... \r", inFileName); - { - size_t readSize = fread(origBuff, 1, benchedSize, inFile); - fclose(inFile); - if (readSize != benchedSize) { - DISPLAY("\nError: problem reading file '%s' !! \n", inFileName); - free(origBuff); - return 13; + { U64 const inFileSize = UTIL_getFileSize(inFileName); + if (inFileSize == UTIL_FILESIZE_UNKNOWN) { + DISPLAY( "Cannot measure size of %s\n", inFileName); + fclose(inFile); + return 11; + } + benchedSize = BMK_findMaxMem(inFileSize*3) / 3; + if ((U64)benchedSize > inFileSize) + benchedSize = (size_t)inFileSize; + if ((U64)benchedSize < inFileSize) { + DISPLAY("Not enough memory for '%s' full size; testing %u MB only...\n", + inFileName, (U32)(benchedSize>>20)); } } - /* bench */ - DISPLAY("\r%79s\r", ""); - DISPLAY(" %s : \n", inFileName); - if (benchNb) - benchMem(origBuff, benchedSize, benchNb, cLevel, cparams); - else - for (benchNb=0; benchNb<100; benchNb++) benchMem(origBuff, benchedSize, benchNb, cLevel, cparams); + /* Alloc */ + { void* const origBuff = malloc(benchedSize); + if (!origBuff) { DISPLAY("\nError: not enough memory!\n"); fclose(inFile); return 12; } - free(origBuff); - } + /* Fill input buffer */ + DISPLAY("Loading %s... \r", inFileName); + { 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%70s\r", ""); /* blank line */ + DISPLAY(" %s : \n", inFileName); + if (benchNb) { + benchMem(benchNb, origBuff, benchedSize, cLevel, cparams); + } else { + for (benchNb=0; benchNb<100; benchNb++) { + benchMem(benchNb, origBuff, benchedSize, cLevel, cparams); + } } + + free(origBuff); + } } return 0; } @@ -649,7 +661,7 @@ static int badusage(const char* exename) int main(int argc, const char** argv) { - int i, filenamesStart=0, result; + int argNb, filenamesStart=0, result; const char* exename = argv[0]; const char* input_filename = NULL; U32 benchNb = 0, main_pause = 0; @@ -659,8 +671,8 @@ int main(int argc, const char** argv) DISPLAY(WELCOME_MESSAGE); if (argc<1) return badusage(exename); - for(i=1; i