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
|
|
|
|
2018-08-23 23:03:30 +00:00
|
|
|
/* === Dependencies === */
|
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-08-23 23:03:30 +00:00
|
|
|
|
|
|
|
/* === 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`.
|
2018-06-15 20:21:08 +00:00
|
|
|
*/
|
2018-08-23 23:03:30 +00:00
|
|
|
#define VARIANT_ERROR_RESULT(baseType, variantName) \
|
2018-08-23 21:21:18 +00:00
|
|
|
\
|
|
|
|
typedef struct { \
|
|
|
|
baseType internal_never_use_directly; \
|
|
|
|
int tag; \
|
|
|
|
} variantName
|
|
|
|
|
2018-06-12 19:54:43 +00:00
|
|
|
|
2018-06-04 23:32:37 +00:00
|
|
|
typedef struct {
|
|
|
|
size_t cSize;
|
2018-08-22 01:19:27 +00:00
|
|
|
unsigned long long cSpeed; /* bytes / sec */
|
|
|
|
unsigned long long dSpeed;
|
2018-08-23 21:21:18 +00:00
|
|
|
size_t cMem; /* ? what is reported ? */
|
|
|
|
} BMK_benchResult_t;
|
|
|
|
|
2018-08-23 23:03:30 +00:00
|
|
|
VARIANT_ERROR_RESULT(BMK_benchResult_t, BMK_benchOutcome_t);
|
2018-08-23 21:21:18 +00:00
|
|
|
|
|
|
|
/* check first if the return structure represents an error or a valid result */
|
2018-08-23 23:03:30 +00:00
|
|
|
int BMK_isSuccessful_benchOutcome(BMK_benchOutcome_t outcome);
|
2018-08-23 21:21:18 +00:00
|
|
|
|
|
|
|
/* extract result from variant type.
|
|
|
|
* note : this function will abort() program execution if result is not valid
|
2018-08-23 23:03:30 +00:00
|
|
|
* check result validity first, by using BMK_isSuccessful_benchOutcome()
|
2018-08-23 21:21:18 +00:00
|
|
|
*/
|
2018-08-23 23:03:30 +00:00
|
|
|
BMK_benchResult_t BMK_extract_benchResult(BMK_benchOutcome_t outcome);
|
2018-06-04 23:32:37 +00:00
|
|
|
|
2018-06-12 19:54:43 +00:00
|
|
|
|
2018-08-22 01:19:27 +00:00
|
|
|
/*! BMK_benchFiles() -- called by zstdcli */
|
|
|
|
/* Loads files from fileNamesTable into memory,
|
2018-08-23 23:03:30 +00:00
|
|
|
* and an optional dictionary from dictFileName (can be NULL),
|
2018-08-22 01:19:27 +00:00
|
|
|
* then uses benchMem().
|
2018-08-23 23:03:30 +00:00
|
|
|
* 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:
|
2018-08-22 01:19:27 +00:00
|
|
|
* 0 : no display;
|
|
|
|
* 1 : errors;
|
|
|
|
* 2 : + result + interaction + warnings;
|
2018-08-23 23:03:30 +00:00
|
|
|
* 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
|
2018-06-12 19:54:43 +00:00
|
|
|
*/
|
2018-08-23 21:21:18 +00:00
|
|
|
BMK_benchOutcome_t BMK_benchFiles(
|
|
|
|
const char* const * fileNamesTable, unsigned nbFiles,
|
2018-08-22 01:19:27 +00:00
|
|
|
const char* dictFileName,
|
|
|
|
int cLevel, const ZSTD_compressionParameters* compressionParams,
|
2018-06-15 20:21:08 +00:00
|
|
|
int displayLevel);
|
|
|
|
|
2018-06-23 00:25:16 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
BMK_both = 0,
|
|
|
|
BMK_decodeOnly = 1,
|
|
|
|
BMK_compressOnly = 2
|
|
|
|
} BMK_mode_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
BMK_mode_t mode; /* 0: all, 1: compress only 2: decode only */
|
|
|
|
unsigned nbSeconds; /* default timing is in nbSeconds */
|
2018-08-23 23:03:30 +00:00
|
|
|
size_t blockSize; /* Maximum size of each block*/
|
2018-06-23 00:25:16 +00:00
|
|
|
unsigned nbWorkers; /* multithreading */
|
|
|
|
unsigned realTime; /* real time priority */
|
|
|
|
int additionalParam; /* used by python speed benchmark */
|
|
|
|
unsigned ldmFlag; /* enables long distance matching */
|
2018-08-23 23:03:30 +00:00
|
|
|
unsigned ldmMinMatch; /* below: parameters for long distance matching, see zstd.1.md */
|
2018-08-22 01:19:27 +00:00
|
|
|
unsigned ldmHashLog;
|
2018-06-23 00:25:16 +00:00
|
|
|
unsigned ldmBucketSizeLog;
|
|
|
|
unsigned ldmHashEveryLog;
|
|
|
|
} BMK_advancedParams_t;
|
|
|
|
|
|
|
|
/* returns default parameters used by nonAdvanced functions */
|
|
|
|
BMK_advancedParams_t BMK_initAdvancedParams(void);
|
|
|
|
|
2018-08-22 01:19:27 +00:00
|
|
|
/*! BMK_benchFilesAdvanced():
|
|
|
|
* Same as BMK_benchFiles(),
|
|
|
|
* with more controls, provided through advancedParams_t structure */
|
2018-08-23 21:21:18 +00:00
|
|
|
BMK_benchOutcome_t BMK_benchFilesAdvanced(
|
|
|
|
const char* const * fileNamesTable, unsigned nbFiles,
|
2018-08-22 01:19:27 +00:00
|
|
|
const char* dictFileName,
|
|
|
|
int cLevel, const ZSTD_compressionParameters* compressionParams,
|
|
|
|
int displayLevel, const BMK_advancedParams_t* adv);
|
|
|
|
|
|
|
|
/*! BMK_syntheticTest() -- called from zstdcli */
|
|
|
|
/* Generates a sample with datagen, using 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:
|
2018-08-23 23:03:30 +00:00
|
|
|
* 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
|
2018-06-19 17:58:22 +00:00
|
|
|
*/
|
2018-08-23 21:21:18 +00:00
|
|
|
BMK_benchOutcome_t BMK_syntheticTest(
|
|
|
|
int cLevel, double compressibility,
|
2018-06-19 17:58:22 +00:00
|
|
|
const ZSTD_compressionParameters* compressionParams,
|
2018-08-24 22:59:57 +00:00
|
|
|
int displayLevel, const BMK_advancedParams_t* adv);
|
2018-06-19 17:58:22 +00:00
|
|
|
|
2018-08-23 21:21:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* === Benchmark Zstandard in a memory-to-memory scenario === */
|
|
|
|
|
2018-08-22 01:19:27 +00:00
|
|
|
/** BMK_benchMem() -- core benchmarking function, called in paramgrill
|
|
|
|
* applies ZSTD_compress_generic() and ZSTD_decompress_generic() on data in srcBuffer
|
|
|
|
* with specific compression parameters provided by other arguments using benchFunction
|
|
|
|
* (cLevel, comprParams + adv in advanced Mode) */
|
|
|
|
/* srcBuffer - data source, expected to be valid compressed data if in Decode Only Mode
|
|
|
|
* srcSize - size of data in srcBuffer
|
|
|
|
* fileSizes - srcBuffer is considered cut into 1+ segments, to compress separately.
|
|
|
|
* note : sum(fileSizes) must be == srcSize. (<== ensure it's properly checked)
|
|
|
|
* nbFiles - nb of segments
|
|
|
|
* cLevel - compression level
|
|
|
|
* comprParams - basic compression parameters
|
|
|
|
* dictBuffer - a dictionary if used, null otherwise
|
|
|
|
* dictBufferSize - size of dictBuffer, 0 otherwise
|
|
|
|
* diplayLevel - see BMK_benchFiles
|
|
|
|
* displayName - name used by display
|
2018-08-23 23:03:30 +00:00
|
|
|
* @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
|
2018-06-12 19:54:43 +00:00
|
|
|
*/
|
2018-08-23 21:21:18 +00:00
|
|
|
BMK_benchOutcome_t BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
2018-06-11 14:59:05 +00:00
|
|
|
const size_t* fileSizes, unsigned nbFiles,
|
2018-08-22 01:19:27 +00:00
|
|
|
int cLevel, const ZSTD_compressionParameters* comprParams,
|
2018-06-11 14:59:05 +00:00
|
|
|
const void* dictBuffer, size_t dictBufferSize,
|
|
|
|
int displayLevel, const char* displayName);
|
2018-06-04 23:32:37 +00:00
|
|
|
|
2018-08-22 01:19:27 +00:00
|
|
|
/* BMK_benchMemAdvanced() : same as BMK_benchMem()
|
|
|
|
* with following additional options :
|
2018-07-16 23:16:31 +00:00
|
|
|
* dstBuffer - destination buffer to write compressed output in, NULL if none provided.
|
|
|
|
* dstCapacity - capacity of destination buffer, give 0 if dstBuffer = NULL
|
2018-08-22 01:19:27 +00:00
|
|
|
* adv = see advancedParams_t
|
2018-07-16 23:16:31 +00:00
|
|
|
*/
|
2018-08-23 21:21:18 +00:00
|
|
|
BMK_benchOutcome_t BMK_benchMemAdvanced(const void* srcBuffer, size_t srcSize,
|
2018-08-22 01:19:27 +00:00
|
|
|
void* dstBuffer, size_t dstCapacity,
|
2018-06-12 19:54:43 +00:00
|
|
|
const size_t* fileSizes, unsigned nbFiles,
|
2018-08-22 01:19:27 +00:00
|
|
|
int cLevel, const ZSTD_compressionParameters* comprParams,
|
2018-06-12 19:54:43 +00:00
|
|
|
const void* dictBuffer, size_t dictBufferSize,
|
|
|
|
int displayLevel, const char* displayName,
|
|
|
|
const BMK_advancedParams_t* adv);
|
|
|
|
|
2018-08-23 21:21:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* ==== Benchmarking any function, iterated on a set of blocks ==== */
|
|
|
|
|
2018-06-23 00:25:16 +00:00
|
|
|
typedef struct {
|
2018-08-23 21:21:18 +00:00
|
|
|
unsigned long long nanoSecPerRun; /* time per iteration */
|
|
|
|
size_t sumOfReturn; /* sum of return values */
|
|
|
|
} BMK_runTime_t;
|
|
|
|
|
2018-08-23 23:03:30 +00:00
|
|
|
VARIANT_ERROR_RESULT(BMK_runTime_t, BMK_runOutcome_t);
|
2018-06-23 00:25:16 +00:00
|
|
|
|
2018-08-23 21:21:18 +00:00
|
|
|
/* check first if the return structure represents an error or a valid result */
|
|
|
|
int BMK_isSuccessful_runOutcome(BMK_runOutcome_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_isSuccessful_runOutcome()
|
|
|
|
*/
|
|
|
|
BMK_runTime_t BMK_extract_runTime(BMK_runOutcome_t outcome);
|
|
|
|
|
|
|
|
|
2018-08-25 00:28:38 +00:00
|
|
|
|
2018-08-23 21:21:18 +00:00
|
|
|
typedef size_t (*BMK_benchFn_t)(const void* src, size_t srcSize, void* dst, size_t dstCapacity, void* customPayload);
|
|
|
|
typedef size_t (*BMK_initFn_t)(void* initPayload);
|
2018-06-23 00:25:16 +00:00
|
|
|
|
|
|
|
|
2018-08-23 21:21:18 +00:00
|
|
|
/* BMK_benchFunction() :
|
|
|
|
* 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-23 00:25:16 +00:00
|
|
|
* is run nbLoops times
|
2018-08-23 21:21:18 +00:00
|
|
|
* initFn - (*initFn)(initPayload) is run once per benchmark, at the beginning.
|
|
|
|
* This argument can be NULL, in which case nothing is run.
|
2018-08-22 01:19:27 +00:00
|
|
|
* blockCount - number of blocks. Size of all array parameters : srcBuffers, srcSizes, dstBuffers, dstCapacities, blockResults
|
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
|
2018-07-27 15:49:25 +00:00
|
|
|
* dstCapacities - an array of the capacities of above buffers
|
2018-08-27 02:29:12 +00:00
|
|
|
* blockResults - Optional: store the return value of benchFn for each block. Use NULL if this result is not requested.
|
2018-06-23 00:25:16 +00:00
|
|
|
* nbLoops - defines number of times benchFn is run.
|
2018-08-23 23:03:30 +00:00
|
|
|
* @return: a variant, which express either an error, or can generate a valid BMK_runTime_t result.
|
2018-08-23 21:21:18 +00:00
|
|
|
* Use BMK_isSuccessful_runOutcome() to check if function was successful.
|
|
|
|
* If yes, extract the result with BMK_extract_runTime(),
|
|
|
|
* it will contain :
|
|
|
|
* .sumOfReturn : the sum of all return values of benchFn through all of blocks
|
|
|
|
* .nanoSecPerRun : time per run of benchFn + (time for initFn / nbLoops)
|
|
|
|
* .sumOfReturn is generally intended for functions which return a # of bytes written into dstBuffer,
|
|
|
|
* in which case, this value will be the total amount of bytes written into dstBuffer.
|
2018-06-15 20:21:08 +00:00
|
|
|
*/
|
2018-08-23 21:21:18 +00:00
|
|
|
BMK_runOutcome_t BMK_benchFunction(
|
|
|
|
BMK_benchFn_t benchFn, void* benchPayload,
|
2018-06-23 00:25:16 +00:00
|
|
|
BMK_initFn_t initFn, void* initPayload,
|
2018-06-18 19:08:51 +00:00
|
|
|
size_t blockCount,
|
2018-08-22 01:19:27 +00:00
|
|
|
const void *const * srcBuffers, const size_t* srcSizes,
|
2018-08-23 21:21:18 +00:00
|
|
|
void *const * dstBuffers, const size_t* dstCapacities,
|
|
|
|
size_t* blockResults,
|
2018-06-23 00:25:16 +00:00
|
|
|
unsigned nbLoops);
|
2015-01-24 00:58:16 +00:00
|
|
|
|
2018-06-23 00:25:16 +00:00
|
|
|
|
2018-08-23 21:21:18 +00:00
|
|
|
|
2018-08-28 18:21:09 +00:00
|
|
|
/* ==== Benchmark any function, providing intermediate results ==== */
|
2018-08-23 21:21:18 +00:00
|
|
|
|
2018-08-28 18:21:09 +00:00
|
|
|
/* state information tracking benchmark session */
|
2018-08-23 21:21:18 +00:00
|
|
|
typedef struct BMK_timedFnState_s BMK_timedFnState_t;
|
|
|
|
|
2018-08-28 18:21:09 +00:00
|
|
|
/* BMK_createTimedFnState() and BMK_resetTimedFnState() :
|
|
|
|
* Create/Set BMK_timedFnState_t for next benchmark session,
|
|
|
|
* which shall last a minimum of total_ms milliseconds,
|
|
|
|
* producing intermediate results, paced at interval of (approximately) run_ms.
|
|
|
|
*/
|
|
|
|
BMK_timedFnState_t* BMK_createTimedFnState(unsigned total_ms, unsigned run_ms);
|
|
|
|
void BMK_resetTimedFnState(BMK_timedFnState_t* timedFnState, unsigned total_ms, unsigned run_ms);
|
2018-08-22 01:19:27 +00:00
|
|
|
void BMK_freeTimedFnState(BMK_timedFnState_t* state);
|
2018-06-21 18:16:53 +00:00
|
|
|
|
|
|
|
|
2018-08-28 18:21:09 +00:00
|
|
|
/* Tells if duration of all benchmark runs has exceeded total_ms
|
|
|
|
*/
|
|
|
|
int BMK_isCompleted_TimedFn(const BMK_timedFnState_t* timedFnState);
|
|
|
|
|
|
|
|
|
2018-08-27 04:30:18 +00:00
|
|
|
/* BMK_benchTimedFn() :
|
2018-08-28 18:21:09 +00:00
|
|
|
* Similar to BMK_benchFunction(), most arguments being identical.
|
|
|
|
* Automatically determines `nbLoops` so that each result is regularly produced at interval of about run_ms.
|
|
|
|
* Note : minimum `nbLoops` is 1, therefore a run may last more than run_ms, and possibly even more than total_ms.
|
|
|
|
* Usage - initialize timedFnState, select benchmark duration (total_ms) and each measurement duration (run_ms)
|
|
|
|
* call BMK_benchTimedFn() repetitively, each measurement is supposed to last about run_ms
|
|
|
|
* Check if total time budget is spent or exceeded, using BMK_isCompleted_TimedFn()
|
2018-06-21 18:16:53 +00:00
|
|
|
*/
|
2018-08-27 04:30:18 +00:00
|
|
|
BMK_runOutcome_t BMK_benchTimedFn(
|
2018-08-25 00:28:38 +00:00
|
|
|
BMK_timedFnState_t* timedFnState,
|
|
|
|
BMK_benchFn_t benchFn, void* benchPayload,
|
|
|
|
BMK_initFn_t initFn, void* initPayload,
|
|
|
|
size_t blockCount,
|
|
|
|
const void *const * srcBlockBuffers, const size_t* srcBlockSizes,
|
|
|
|
void *const * dstBlockBuffers, const size_t* dstBlockCapacities,
|
|
|
|
size_t* blockResults);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-21 18:16:53 +00:00
|
|
|
|
2016-12-07 00:49:23 +00:00
|
|
|
#endif /* BENCH_H_121279284357 */
|
2018-06-11 14:59:05 +00:00
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|