From: Yann Collet Date: Thu, 23 Aug 2018 23:03:30 +0000 (-0700) Subject: introduced MB_UNIT X-Git-Tag: v0.0.29~26^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f9ec136212672b1f4ac401611ed39e61bc5ae38;p=thirdparty%2Fzstd.git introduced MB_UNIT so that all benchmarking programs use the same speed scale --- diff --git a/programs/bench.c b/programs/bench.c index ba6a9ca86..9c35bd5ff 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -667,7 +667,7 @@ static BMK_benchOutcome_t BMK_benchMemAdvancedNoAlloc( DISPLAYLEVEL(2, "%2s-%-17.17s :%10u ->%10u (%5.*f),%6.*f MB/s\r", marks[markNb], displayName, (U32)srcSize, (U32)cSize, ratioAccuracy, ratio, - benchResult.cSpeed < (10 MB) ? 2 : 1, (double)benchResult.cSpeed / (1 MB)); + benchResult.cSpeed < (10 MB) ? 2 : 1, (double)benchResult.cSpeed / MB_UNIT); } } @@ -695,7 +695,7 @@ static BMK_benchOutcome_t BMK_benchMemAdvancedNoAlloc( DISPLAYLEVEL(2, "%2s-%-17.17s :%10u ->%10u (%5.*f),%6.*f MB/s ,%6.1f MB/s \r", marks[markNb], displayName, (U32)srcSize, (U32)benchResult.cSize, ratioAccuracy, ratio, - benchResult.cSpeed < (10 MB) ? 2 : 1, (double)benchResult.cSpeed / (1 MB), + benchResult.cSpeed < (10 MB) ? 2 : 1, (double)benchResult.cSpeed / MB_UNIT, (double)benchResult.dSpeed / (1 MB)); } } @@ -742,8 +742,8 @@ static BMK_benchOutcome_t BMK_benchMemAdvancedNoAlloc( } /* CRC Checking */ if (displayLevel == 1) { /* hidden display mode -q, used by python speed benchmark */ - double const cSpeed = (double)benchResult.cSpeed / (1 MB); - double const dSpeed = (double)benchResult.dSpeed / (1 MB); + double const cSpeed = (double)benchResult.cSpeed / MB_UNIT; + double const dSpeed = (double)benchResult.dSpeed / MB_UNIT; if (adv->additionalParam) { DISPLAY("-%-3i%11i (%5.3f) %6.2f MB/s %6.1f MB/s %s (param=%d)\n", cLevel, (int)cSize, ratio, cSpeed, dSpeed, displayName, adv->additionalParam); } else { diff --git a/programs/bench.h b/programs/bench.h index be5998e2c..214ab9b25 100644 --- a/programs/bench.h +++ b/programs/bench.h @@ -15,18 +15,25 @@ extern "C" { #ifndef BENCH_H_121279284357 #define BENCH_H_121279284357 +/* === Dependencies === */ #include /* size_t */ #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */ #include "zstd.h" /* ZSTD_compressionParameters */ -/* Creates a struct type typeName, featuring: - * - an .error field of type int - * - a .result field of some baseType. - * Functions with return type typeName - * will either be successful, with .error = 0, providing a valid .result, - * or return an error, with .error != 0, in which case .result is invalid. + +/* === Constants === */ + +#define MB_UNIT 1000000 + + +/* === Benchmark functions === */ + +/* Creates a variant `typeName`, able to express "error or valid result". + * Functions with return type `typeName` + * must first check if result is valid, using BMK_isSuccessful_*(), + * and only then can extract `baseType`. */ -#define SUMTYPE_ERROR_RESULT(baseType, variantName) \ +#define VARIANT_ERROR_RESULT(baseType, variantName) \ \ typedef struct { \ baseType internal_never_use_directly; \ @@ -41,38 +48,42 @@ typedef struct { size_t cMem; /* ? what is reported ? */ } BMK_benchResult_t; -SUMTYPE_ERROR_RESULT(BMK_benchResult_t, BMK_benchOutcome_t); +VARIANT_ERROR_RESULT(BMK_benchResult_t, BMK_benchOutcome_t); /* check first if the return structure represents an error or a valid result */ -int BMK_isSuccessful_benchOutcome(BMK_benchOutcome_t errorOrResult); +int BMK_isSuccessful_benchOutcome(BMK_benchOutcome_t outcome); /* extract result from variant type. * note : this function will abort() program execution if result is not valid - * check result validity first, by using BMK_isValid_benchResult() + * check result validity first, by using BMK_isSuccessful_benchOutcome() */ -BMK_benchResult_t BMK_extract_benchResult(BMK_benchOutcome_t errorOrResult); +BMK_benchResult_t BMK_extract_benchResult(BMK_benchOutcome_t outcome); /*! BMK_benchFiles() -- called by zstdcli */ /* Loads files from fileNamesTable into memory, - * loads dictionary from dictFileName, + * and an optional dictionary from dictFileName (can be NULL), * then uses benchMem(). - * fileNamesTable - name of files to benchmark - * nbFiles - number of files (size of fileNamesTable), must be > 0 (what happens if not ?) - * dictFileName - name of dictionary file to load - * cLevel - compression level to benchmark, errors if invalid - * compressionParams - advanced compression Parameters - * displayLevel - what gets printed + * fileNamesTable - name of files to benchmark. + * nbFiles - number of files (size of fileNamesTable), must be > 0. + * dictFileName - name of dictionary file to load. + * cLevel - compression level to benchmark, errors if invalid. + * compressionParams - advanced compression Parameters. + * displayLevel - what gets printed: * 0 : no display; * 1 : errors; * 2 : + result + interaction + warnings; - * 3 : + progression; - * 4 : + information - * @return - * .error will give a nonzero error value if an error has occured - * .result - only valid if .error = 0, - * .result will return compression speed (.cSpeed), - * decompression speed (.dSpeed), and compressed size (.cSize). + * 3 : + information; + * 4 : + debug + * @return: + * a variant, which expresses either an error, or a valid result. + * Use BMK_isSuccessful_benchOutcome() to check if function was successful. + * If yes, extract the valid result with BMK_extract_benchResult(), + * it will contain : + * .cSpeed: compression speed in bytes per second, + * .dSpeed: decompression speed in bytes per second, + * .cSize : compressed size, in bytes + * .cMem : memory budget required for the compression context */ BMK_benchOutcome_t BMK_benchFiles( const char* const * fileNamesTable, unsigned nbFiles, @@ -90,12 +101,12 @@ typedef enum { typedef struct { BMK_mode_t mode; /* 0: all, 1: compress only 2: decode only */ unsigned nbSeconds; /* default timing is in nbSeconds */ - size_t blockSize; /* Maximum allowable size of a block*/ + size_t blockSize; /* Maximum size of each block*/ unsigned nbWorkers; /* multithreading */ unsigned realTime; /* real time priority */ int additionalParam; /* used by python speed benchmark */ unsigned ldmFlag; /* enables long distance matching */ - unsigned ldmMinMatch; /* below: parameters for long distance matching, see zstd.1.md for meaning */ + unsigned ldmMinMatch; /* below: parameters for long distance matching, see zstd.1.md */ unsigned ldmHashLog; unsigned ldmBucketSizeLog; unsigned ldmHashEveryLog; @@ -121,10 +132,14 @@ BMK_benchOutcome_t BMK_benchFilesAdvanced( * displayLevel - see benchFiles * adv - see advanced_Params_t * @return: - * .error will give a nonzero error value if an error has occured - * .result - only valid if .error = 0, - * .result will return the compression speed (.cSpeed), - * decompression speed (.dSpeed), and compressed size (.cSize). + * a variant, which expresses either an error, or a valid result. + * Use BMK_isSuccessful_benchOutcome() to check if function was successful. + * If yes, extract the valid result with BMK_extract_benchResult(), + * it will contain : + * .cSpeed: compression speed in bytes per second, + * .dSpeed: decompression speed in bytes per second, + * .cSize : compressed size, in bytes + * .cMem : memory budget required for the compression context */ BMK_benchOutcome_t BMK_syntheticTest( int cLevel, double compressibility, @@ -150,11 +165,15 @@ BMK_benchOutcome_t BMK_syntheticTest( * dictBufferSize - size of dictBuffer, 0 otherwise * diplayLevel - see BMK_benchFiles * displayName - name used by display - * @return - * .error will give a nonzero value if an error has occured - * .result - only valid if .error = 0, - * provide the same results as benchFiles() - * but for the data stored in srcBuffer + * @return: + * a variant, which expresses either an error, or a valid result. + * Use BMK_isSuccessful_benchOutcome() to check if function was successful. + * If yes, extract the valid result with BMK_extract_benchResult(), + * it will contain : + * .cSpeed: compression speed in bytes per second, + * .dSpeed: decompression speed in bytes per second, + * .cSize : compressed size, in bytes + * .cMem : memory budget required for the compression context */ BMK_benchOutcome_t BMK_benchMem(const void* srcBuffer, size_t srcSize, const size_t* fileSizes, unsigned nbFiles, @@ -185,7 +204,7 @@ typedef struct { size_t sumOfReturn; /* sum of return values */ } BMK_runTime_t; -SUMTYPE_ERROR_RESULT(BMK_runTime_t, BMK_runOutcome_t); +VARIANT_ERROR_RESULT(BMK_runTime_t, BMK_runOutcome_t); /* check first if the return structure represents an error or a valid result */ int BMK_isSuccessful_runOutcome(BMK_runOutcome_t outcome); @@ -215,7 +234,7 @@ typedef size_t (*BMK_initFn_t)(void* initPayload); * dstCapacities - an array of the capacities of above buffers * blockResults - store the return value of benchFn for each block. Optional. Use NULL if this result is not requested. * nbLoops - defines number of times benchFn is run. - * @return: a variant, which can be an error, or a BMK_runTime_t result. + * @return: a variant, which express either an error, or can generate a valid BMK_runTime_t result. * Use BMK_isSuccessful_runOutcome() to check if function was successful. * If yes, extract the result with BMK_extract_runTime(), * it will contain : @@ -245,7 +264,7 @@ void BMK_resetTimedFnState(BMK_timedFnState_t* timedFnState, unsigned nbSeconds) void BMK_freeTimedFnState(BMK_timedFnState_t* state); /* define timedFnOutcome */ -SUMTYPE_ERROR_RESULT(BMK_runTime_t, BMK_timedFnOutcome_t); +VARIANT_ERROR_RESULT(BMK_runTime_t, BMK_timedFnOutcome_t); /* check first if the return structure represents an error or a valid result */ int BMK_isSuccessful_timedFnOutcome(BMK_timedFnOutcome_t outcome); diff --git a/tests/fullbench.c b/tests/fullbench.c index 2198f41da..1e63101a4 100644 --- a/tests/fullbench.c +++ b/tests/fullbench.c @@ -529,7 +529,7 @@ static size_t benchMem(U32 benchNb, } { 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 ); + DISPLAY("%2u#%-25.25s:%7.1f MB/s (%7u) \n", benchNb, benchName, (double)srcSize * 1000000000 / result.nanoSecPerRun / MB_UNIT, (unsigned)result.sumOfReturn ); } } _cleanOut: