2017-08-18 23:52:05 +00:00
|
|
|
/*
|
2016-08-30 17:04:33 +00:00
|
|
|
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2017-08-18 23:52:05 +00:00
|
|
|
* This source code is licensed under both the BSD-style license (found in the
|
|
|
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
|
|
* in the COPYING file in the root directory of this source tree).
|
2017-09-08 07:09:23 +00:00
|
|
|
* You may select, at your option, one of the above-listed licenses.
|
2016-08-30 17:04:33 +00:00
|
|
|
*/
|
2015-01-24 00:58:16 +00:00
|
|
|
|
2018-06-11 14:59:05 +00:00
|
|
|
#if defined (__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2015-01-24 00:58:16 +00:00
|
|
|
|
2016-05-31 00:29:45 +00:00
|
|
|
#ifndef BENCH_H_121279284357
|
|
|
|
#define BENCH_H_121279284357
|
2015-01-24 00:58:16 +00:00
|
|
|
|
2016-12-07 00:49:23 +00:00
|
|
|
#include <stddef.h> /* size_t */
|
2016-12-13 12:03:41 +00:00
|
|
|
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */
|
|
|
|
#include "zstd.h" /* ZSTD_compressionParameters */
|
2015-01-24 00:58:16 +00:00
|
|
|
|
2018-06-15 20:21:08 +00:00
|
|
|
/* Creates a struct of type typeName with an int type .error field
|
|
|
|
* and a .result field of some baseType. Functions with return
|
|
|
|
* typeName pass a successful result with .error = 0 and .result
|
|
|
|
* with the intended result, while returning an error will result
|
|
|
|
* in .error != 0.
|
|
|
|
*/
|
2018-06-12 19:54:43 +00:00
|
|
|
#define ERROR_STRUCT(baseType, typeName) typedef struct { \
|
|
|
|
int error; \
|
|
|
|
baseType result; \
|
|
|
|
} typeName
|
|
|
|
|
2018-06-04 23:32:37 +00:00
|
|
|
typedef struct {
|
|
|
|
size_t cSize;
|
|
|
|
double cSpeed; /* bytes / sec */
|
|
|
|
double dSpeed;
|
|
|
|
} BMK_result_t;
|
|
|
|
|
2018-06-11 14:59:05 +00:00
|
|
|
typedef struct {
|
2018-06-15 20:21:08 +00:00
|
|
|
size_t sumOfReturn; /* sum of return values */
|
|
|
|
U64 nanoSecPerRun; /* time per iteration */
|
2018-06-12 19:54:43 +00:00
|
|
|
} BMK_customResult_t;
|
2018-06-19 17:58:22 +00:00
|
|
|
//we might need a nbRuns or nbSecs if we're keeping timeMode / iterMode respectively.
|
|
|
|
//give benchMem responsibility to incrementally update display.
|
2018-06-12 19:54:43 +00:00
|
|
|
|
|
|
|
ERROR_STRUCT(BMK_result_t, BMK_return_t);
|
|
|
|
ERROR_STRUCT(BMK_customResult_t, BMK_customReturn_t);
|
|
|
|
|
2018-06-15 20:21:08 +00:00
|
|
|
typedef enum {
|
|
|
|
BMK_timeMode = 0,
|
|
|
|
BMK_iterMode = 1
|
|
|
|
} BMK_loopMode_t;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
BMK_both = 0,
|
|
|
|
BMK_decodeOnly = 1,
|
|
|
|
BMK_compressOnly = 2
|
|
|
|
} BMK_mode_t;
|
|
|
|
|
2018-06-12 19:54:43 +00:00
|
|
|
typedef struct {
|
2018-06-14 18:46:17 +00:00
|
|
|
BMK_mode_t mode; /* 0: all, 1: compress only 2: decode only */
|
|
|
|
BMK_loopMode_t loopMode; /* if loopmode, then nbSeconds = nbLoops */
|
2018-06-15 20:21:08 +00:00
|
|
|
unsigned nbSeconds; /* default timing is in nbSeconds */
|
2018-06-12 19:54:43 +00:00
|
|
|
size_t blockSize; /* Maximum allowable size of a block*/
|
|
|
|
unsigned nbWorkers; /* multithreading */
|
2018-06-15 20:21:08 +00:00
|
|
|
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 ldmHashLog;
|
2018-06-12 19:54:43 +00:00
|
|
|
unsigned ldmBucketSizeLog;
|
|
|
|
unsigned ldmHashEveryLog;
|
|
|
|
} BMK_advancedParams_t;
|
|
|
|
|
|
|
|
/* returns default parameters used by nonAdvanced functions */
|
2018-06-15 20:21:08 +00:00
|
|
|
BMK_advancedParams_t BMK_initAdvancedParams(void);
|
2018-06-12 19:54:43 +00:00
|
|
|
|
2018-06-15 20:21:08 +00:00
|
|
|
/* called in cli */
|
2018-06-18 22:06:31 +00:00
|
|
|
/* Loads files in fileNamesTable into memory, as well as a dictionary
|
|
|
|
* from dictFileName, and then uses benchMem */
|
2018-06-15 20:21:08 +00:00
|
|
|
/* fileNamesTable - name of files to benchmark
|
2018-06-19 17:58:22 +00:00
|
|
|
* nbFiles - number of files (size of fileNamesTable), must be > 0
|
2018-06-15 20:21:08 +00:00
|
|
|
* dictFileName - name of dictionary file to load
|
2018-06-18 22:06:31 +00:00
|
|
|
* cLevel - compression level to benchmark, errors if invalid
|
2018-06-15 20:21:08 +00:00
|
|
|
* compressionParams - basic compression Parameters
|
2018-06-12 19:54:43 +00:00
|
|
|
* displayLevel - what gets printed
|
|
|
|
* 0 : no display;
|
|
|
|
* 1 : errors;
|
|
|
|
* 2 : + result + interaction + warnings;
|
|
|
|
* 3 : + progression;
|
|
|
|
* 4 : + information
|
|
|
|
* return
|
2018-06-15 20:21:08 +00:00
|
|
|
* .error will give a nonzero error value if an error has occured
|
|
|
|
* .result - if .error = 0, .result will return the time taken to compression speed
|
2018-06-19 17:58:22 +00:00
|
|
|
* (.cSpeed), decompression speed (.dSpeed), and compressed size (.cSize) of the original
|
2018-06-15 20:21:08 +00:00
|
|
|
* file
|
2018-06-12 19:54:43 +00:00
|
|
|
*/
|
2018-06-19 17:58:22 +00:00
|
|
|
BMK_return_t BMK_benchFiles(const char* const * const fileNamesTable, unsigned const nbFiles,
|
|
|
|
const char* const dictFileName,
|
|
|
|
int const cLevel, const ZSTD_compressionParameters* const compressionParams,
|
2018-06-15 20:21:08 +00:00
|
|
|
int displayLevel);
|
|
|
|
|
|
|
|
/* See benchFiles for normal parameter uses and return, see advancedParams_t for adv */
|
2018-06-19 17:58:22 +00:00
|
|
|
BMK_return_t BMK_benchFilesAdvanced(const char* const * const fileNamesTable, unsigned const nbFiles,
|
|
|
|
const char* const dictFileName,
|
|
|
|
int const cLevel, const ZSTD_compressionParameters* const compressionParams,
|
2018-06-15 20:21:08 +00:00
|
|
|
int displayLevel, const BMK_advancedParams_t* const adv);
|
2018-06-04 23:32:37 +00:00
|
|
|
|
2018-06-19 17:58:22 +00:00
|
|
|
/* called in cli */
|
|
|
|
/* Generates a sample with datagen with the compressibility argument*/
|
|
|
|
/* cLevel - compression level to benchmark, errors if invalid
|
|
|
|
* compressibility - determines compressibility of sample
|
|
|
|
* compressionParams - basic compression Parameters
|
|
|
|
* displayLevel - see benchFiles
|
|
|
|
* adv - see advanced_Params_t
|
|
|
|
* return
|
|
|
|
* .error will give a nonzero error value if an error has occured
|
|
|
|
* .result - if .error = 0, .result will return the time taken to compression speed
|
|
|
|
* (.cSpeed), decompression speed (.dSpeed), and compressed size (.cSize) of the original
|
|
|
|
* file
|
|
|
|
*/
|
|
|
|
BMK_return_t BMK_syntheticTest(int cLevel, double compressibility,
|
|
|
|
const ZSTD_compressionParameters* compressionParams,
|
|
|
|
int displayLevel, const BMK_advancedParams_t * const adv);
|
|
|
|
|
2018-06-18 22:06:31 +00:00
|
|
|
/* basic benchmarking function, called in paramgrill
|
|
|
|
* applies ZSTD_compress_generic() and ZSTD_decompress_generic() on data in srcBuffer
|
|
|
|
* with specific compression parameters specified by other arguments using benchFunction
|
|
|
|
* (cLevel, comprParams + adv in advanced Mode) */
|
2018-06-12 19:54:43 +00:00
|
|
|
/* srcBuffer - data source, expected to be valid compressed data if in Decode Only Mode
|
|
|
|
* srcSize - size of data in srcBuffer
|
|
|
|
* cLevel - compression level
|
|
|
|
* comprParams - basic compression parameters
|
|
|
|
* dictBuffer - a dictionary if used, null otherwise
|
|
|
|
* dictBufferSize - size of dictBuffer, 0 otherwise
|
2018-06-18 22:06:31 +00:00
|
|
|
* ctx - Compression Context (must be provided)
|
|
|
|
* dctx - Decompression Context (must be provided)
|
2018-06-15 20:21:08 +00:00
|
|
|
* diplayLevel - see BMK_benchFiles
|
|
|
|
* displayName - name used by display
|
|
|
|
* return
|
|
|
|
* .error will give a nonzero value if an error has occured
|
|
|
|
* .result - if .error = 0, will give the same results as benchFiles
|
|
|
|
* but for the data stored in srcBuffer
|
2018-06-12 19:54:43 +00:00
|
|
|
*/
|
2018-06-11 14:59:05 +00:00
|
|
|
BMK_return_t BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
|
|
|
const size_t* fileSizes, unsigned nbFiles,
|
|
|
|
const int cLevel, const ZSTD_compressionParameters* comprParams,
|
|
|
|
const void* dictBuffer, size_t dictBufferSize,
|
|
|
|
ZSTD_CCtx* ctx, ZSTD_DCtx* dctx,
|
|
|
|
int displayLevel, const char* displayName);
|
2018-06-04 23:32:37 +00:00
|
|
|
|
2018-06-15 20:21:08 +00:00
|
|
|
/* See benchMem for normal parameter uses and return, see advancedParams_t for adv */
|
2018-06-12 19:54:43 +00:00
|
|
|
BMK_return_t BMK_benchMemAdvanced(const void* srcBuffer, size_t srcSize,
|
|
|
|
const size_t* fileSizes, unsigned nbFiles,
|
|
|
|
const int cLevel, const ZSTD_compressionParameters* comprParams,
|
|
|
|
const void* dictBuffer, size_t dictBufferSize,
|
|
|
|
ZSTD_CCtx* ctx, ZSTD_DCtx* dctx,
|
|
|
|
int displayLevel, const char* displayName,
|
|
|
|
const BMK_advancedParams_t* adv);
|
|
|
|
|
2018-06-18 22:06:31 +00:00
|
|
|
/* This function times the execution of 2 argument functions, benchFn and initFn */
|
2018-06-12 19:54:43 +00:00
|
|
|
|
2018-06-18 19:08:51 +00:00
|
|
|
/* benchFn - (*benchFn)(srcBuffers[i], srcSizes[i], dstBuffers[i], dstCapacities[i], benchPayload)
|
2018-06-21 18:16:53 +00:00
|
|
|
* is run iter times
|
2018-06-18 19:08:51 +00:00
|
|
|
* initFn - (*initFn)(initPayload) is run once per benchmark at the beginning. This argument can
|
|
|
|
* be NULL, in which case nothing is run.
|
|
|
|
* blockCount - number of blocks (size of srcBuffers, srcSizes, dstBuffers, dstCapacities)
|
2018-06-15 20:21:08 +00:00
|
|
|
* srcBuffers - an array of buffers to be operated on by benchFn
|
|
|
|
* srcSizes - an array of the sizes of above buffers
|
|
|
|
* dstBuffers - an array of buffers to be written into by benchFn
|
|
|
|
* dstCapacities - an array of the capacities of above buffers.
|
2018-06-19 17:58:22 +00:00
|
|
|
* iter - defines number of times benchFn is run.
|
2018-06-15 20:21:08 +00:00
|
|
|
* return
|
|
|
|
* .error will give a nonzero value if ZSTD_isError() is nonzero for any of the return
|
|
|
|
* of the calls to initFn and benchFn, or if benchFunction errors internally
|
|
|
|
* .result - if .error = 0, then .result will contain the sum of all return values of
|
|
|
|
* benchFn on the first iteration through all of the blocks (.sumOfReturn) and also
|
|
|
|
* the time per run of benchFn (.nanoSecPerRun). For the former, this
|
|
|
|
* is generally intended to be used on functions which return the # of bytes written
|
|
|
|
* into dstBuffer, hence this value will be the total amount of bytes written to
|
|
|
|
* dstBuffer.
|
|
|
|
*/
|
2018-06-18 19:08:51 +00:00
|
|
|
BMK_customReturn_t BMK_benchFunction(
|
|
|
|
size_t (*benchFn)(const void*, size_t, void*, size_t, void*), void* benchPayload,
|
|
|
|
size_t (*initFn)(void*), void* initPayload,
|
|
|
|
size_t blockCount,
|
2018-06-15 20:21:08 +00:00
|
|
|
const void* const * const srcBuffers, const size_t* srcSizes,
|
|
|
|
void* const * const dstBuffers, const size_t* dstCapacities,
|
2018-06-19 17:58:22 +00:00
|
|
|
unsigned sec);
|
2015-01-24 00:58:16 +00:00
|
|
|
|
2018-06-21 18:16:53 +00:00
|
|
|
typedef struct {
|
|
|
|
unsigned nbLoops;
|
|
|
|
U64 timeRemaining;
|
|
|
|
UTIL_time_t coolTime;
|
|
|
|
} BMK_timeState_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int completed;
|
|
|
|
BMK_customReturn_t intermediateResult; /* since the wrapper can't err, don't need ERROR_STRUCT(cRC, just check here) */
|
|
|
|
BMK_timeState_t state;
|
|
|
|
} BMK_customResultContinuation_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initializes the last argument of benchFunctionTimed, with iter being the number of seconds to bench (see below)
|
|
|
|
*/
|
|
|
|
BMK_customResultContinuation_t BMK_init_customResultContinuation(unsigned iter);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Benchmarks custom functions like BMK_benchFunction(), but runs for iter seconds rather than a fixed number of iterations
|
|
|
|
* arguments mostly the same other than BMK_benchFunction()
|
|
|
|
* Usage - benchFunctionTimed will return in approximately one second, where the intermediate results can be found in
|
|
|
|
* the *cont passed in and be displayed/used as wanted. Keep calling BMK_benchFunctionTimed() until cont->completed = 1
|
|
|
|
* to continue updating intermediate result.
|
|
|
|
*/
|
|
|
|
void BMK_benchFunctionTimed(
|
|
|
|
size_t (*benchFn)(const void*, size_t, void*, size_t, void*), void* benchPayload,
|
|
|
|
size_t (*initFn)(void*), void* initPayload,
|
|
|
|
size_t blockCount,
|
|
|
|
const void* const * const srcBlockBuffers, const size_t* srcBlockSizes,
|
|
|
|
void* const * const dstBlockBuffers, const size_t* dstBlockCapacities,
|
|
|
|
BMK_customResultContinuation_t* cont);
|
|
|
|
|
2016-12-07 00:49:23 +00:00
|
|
|
#endif /* BENCH_H_121279284357 */
|
2018-06-11 14:59:05 +00:00
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|