Introduced ZSTD_getParams()
bench now uses ZSTD_createCDict_advanced()
This commit is contained in:
+16
-12
@@ -200,7 +200,6 @@ ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
|
|||||||
/*--- Dependency ---*/
|
/*--- Dependency ---*/
|
||||||
#include "mem.h" /* U32 */
|
#include "mem.h" /* U32 */
|
||||||
|
|
||||||
|
|
||||||
/*--- Constants ---*/
|
/*--- Constants ---*/
|
||||||
#define ZSTD_MAGICNUMBER 0xFD2FB527 /* v0.7 */
|
#define ZSTD_MAGICNUMBER 0xFD2FB527 /* v0.7 */
|
||||||
#define ZSTD_MAGIC_SKIPPABLE_START 0x184D2A50U
|
#define ZSTD_MAGIC_SKIPPABLE_START 0x184D2A50U
|
||||||
@@ -230,19 +229,19 @@ static const size_t ZSTD_skippableHeaderSize = 8; /* magic number + skippable f
|
|||||||
typedef enum { ZSTD_fast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2, ZSTD_btlazy2, ZSTD_btopt } ZSTD_strategy; /*< from faster to stronger */
|
typedef enum { ZSTD_fast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2, ZSTD_btlazy2, ZSTD_btopt } ZSTD_strategy; /*< from faster to stronger */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
U32 windowLog; /*< largest match distance : larger == more compression, more memory needed during decompression */
|
U32 windowLog; /*< largest match distance : larger == more compression, more memory needed during decompression */
|
||||||
U32 chainLog; /*< fully searched segment : larger == more compression, slower, more memory (useless for fast) */
|
U32 chainLog; /*< fully searched segment : larger == more compression, slower, more memory (useless for fast) */
|
||||||
U32 hashLog; /*< dispatch table : larger == faster, more memory */
|
U32 hashLog; /*< dispatch table : larger == faster, more memory */
|
||||||
U32 searchLog; /*< nb of searches : larger == more compression, slower */
|
U32 searchLog; /*< nb of searches : larger == more compression, slower */
|
||||||
U32 searchLength; /*< match length searched : larger == faster decompression, sometimes less compression */
|
U32 searchLength; /*< match length searched : larger == faster decompression, sometimes less compression */
|
||||||
U32 targetLength; /*< acceptable match size for optimal parser (only) : larger == more compression, slower */
|
U32 targetLength; /*< acceptable match size for optimal parser (only) : larger == more compression, slower */
|
||||||
ZSTD_strategy strategy;
|
ZSTD_strategy strategy;
|
||||||
} ZSTD_compressionParameters;
|
} ZSTD_compressionParameters;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
U32 contentSizeFlag; /*< 1: content size will be in frame header (if known). */
|
U32 contentSizeFlag; /*< 1: content size will be in frame header (if known). */
|
||||||
U32 checksumFlag; /*< 1: will generate a 22-bits checksum at end of frame, to be used for error detection by decompressor */
|
U32 checksumFlag; /*< 1: will generate a 22-bits checksum at end of frame, to be used for error detection by decompressor */
|
||||||
U32 noDictIDFlag; /*< 1: no dict ID will be saved into frame header (if dictionary compression) */
|
U32 noDictIDFlag; /*< 1: no dict ID will be saved into frame header (if dictionary compression) */
|
||||||
} ZSTD_frameParameters;
|
} ZSTD_frameParameters;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -275,15 +274,20 @@ ZSTDLIB_API unsigned ZSTD_maxCLevel (void);
|
|||||||
* `srcSize` value is optional, select 0 if not known */
|
* `srcSize` value is optional, select 0 if not known */
|
||||||
ZSTDLIB_API ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, U64 srcSize, size_t dictSize);
|
ZSTDLIB_API ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, U64 srcSize, size_t dictSize);
|
||||||
|
|
||||||
/*! ZSTD_checkParams() :
|
/*! ZSTD_checkCParams() :
|
||||||
* Ensure param values remain within authorized range */
|
* Ensure param values remain within authorized range */
|
||||||
ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
|
ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
|
||||||
|
|
||||||
/*! ZSTD_adjustParams() :
|
/*! ZSTD_adjustCParams() :
|
||||||
* optimize params for a given `srcSize` and `dictSize`.
|
* optimize params for a given `srcSize` and `dictSize`.
|
||||||
* both values are optional, select `0` if unknown. */
|
* both values are optional, select `0` if unknown. */
|
||||||
ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, U64 srcSize, size_t dictSize);
|
ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, U64 srcSize, size_t dictSize);
|
||||||
|
|
||||||
|
/*! ZSTD_getParams() :
|
||||||
|
* same as ZSTD_getCParams(), but @return a `ZSTD_parameters` object instead of a `ZSTD_compressionParameters`.
|
||||||
|
* All fields of `ZSTD_frameParameters` are set to default (0) */
|
||||||
|
ZSTD_parameters ZSTD_getParams(int compressionLevel, U64 srcSize, size_t dictSize);
|
||||||
|
|
||||||
/*! ZSTD_compress_advanced() :
|
/*! ZSTD_compress_advanced() :
|
||||||
* Same as ZSTD_compress_usingDict(), with fine-tune control of each compression parameter */
|
* Same as ZSTD_compress_usingDict(), with fine-tune control of each compression parameter */
|
||||||
ZSTDLIB_API size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx,
|
ZSTDLIB_API size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx,
|
||||||
|
|||||||
@@ -2586,7 +2586,7 @@ ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictSize, ZSTD_pa
|
|||||||
if (!customMem.customAlloc && !customMem.customFree)
|
if (!customMem.customAlloc && !customMem.customFree)
|
||||||
customMem = defaultCustomMem;
|
customMem = defaultCustomMem;
|
||||||
|
|
||||||
if (!customMem.customAlloc || !customMem.customFree)
|
if (!customMem.customAlloc || !customMem.customFree) /* can't have 1/2 custom alloc/free as NULL */
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
{ ZSTD_CDict* const cdict = (ZSTD_CDict*) customMem.customAlloc(customMem.opaque, sizeof(*cdict));
|
{ ZSTD_CDict* const cdict = (ZSTD_CDict*) customMem.customAlloc(customMem.opaque, sizeof(*cdict));
|
||||||
@@ -2781,3 +2781,14 @@ ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, U64 srcSize, si
|
|||||||
cp = ZSTD_adjustCParams(cp, srcSize, dictSize);
|
cp = ZSTD_adjustCParams(cp, srcSize, dictSize);
|
||||||
return cp;
|
return cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! ZSTD_getParams() :
|
||||||
|
* same as ZSTD_getCParams(), but @return a `ZSTD_parameters` object instead of a `ZSTD_compressionParameters`.
|
||||||
|
* All fields of `ZSTD_frameParameters` are set to default (0) */
|
||||||
|
ZSTD_parameters ZSTD_getParams(int compressionLevel, U64 srcSize, size_t dictSize) {
|
||||||
|
ZSTD_parameters params;
|
||||||
|
ZSTD_compressionParameters const cParams = ZSTD_getCParams(compressionLevel, srcSize, dictSize);
|
||||||
|
memset(¶ms, 0, sizeof(params));
|
||||||
|
params.cParams = cParams;
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|||||||
+7
-4
@@ -155,7 +155,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
|||||||
|
|
||||||
/* checks */
|
/* checks */
|
||||||
if (!compressedBuffer || !resultBuffer || !blockTable || !ctx || !dctx)
|
if (!compressedBuffer || !resultBuffer || !blockTable || !ctx || !dctx)
|
||||||
EXM_THROW(31, "not enough memory");
|
EXM_THROW(31, "allocation error : not enough memory");
|
||||||
|
|
||||||
/* init */
|
/* init */
|
||||||
if (strlen(displayName)>17) displayName += strlen(displayName)-17; /* can only display 17 characters */
|
if (strlen(displayName)>17) displayName += strlen(displayName)-17; /* can only display 17 characters */
|
||||||
@@ -211,12 +211,15 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
|||||||
DISPLAYLEVEL(2, "%2i-%-17.17s :%10u ->\r", testNb, displayName, (U32)srcSize);
|
DISPLAYLEVEL(2, "%2i-%-17.17s :%10u ->\r", testNb, displayName, (U32)srcSize);
|
||||||
memset(compressedBuffer, 0xE5, maxCompressedSize); /* warm up and erase result buffer */
|
memset(compressedBuffer, 0xE5, maxCompressedSize); /* warm up and erase result buffer */
|
||||||
|
|
||||||
UTIL_sleepMilli(1); /* give processor time to other processes */
|
UTIL_sleepMilli(1); /* give processor time to other processes */
|
||||||
UTIL_waitForNextTick(ticksPerSecond);
|
UTIL_waitForNextTick(ticksPerSecond);
|
||||||
UTIL_getTime(&clockStart);
|
UTIL_getTime(&clockStart);
|
||||||
|
|
||||||
{ U32 nbLoops = 0;
|
{ size_t const refSrcSize = (nbBlocks == 1) ? srcSize : 0;
|
||||||
ZSTD_CDict* cdict = ZSTD_createCDict(dictBuffer, dictBufferSize, cLevel);
|
ZSTD_parameters const zparams = ZSTD_getParams(cLevel, refSrcSize, dictBufferSize);
|
||||||
|
ZSTD_customMem const cmem = { NULL, NULL, NULL };
|
||||||
|
U32 nbLoops = 0;
|
||||||
|
ZSTD_CDict* cdict = ZSTD_createCDict_advanced(dictBuffer, dictBufferSize, zparams, cmem);
|
||||||
if (cdict==NULL) EXM_THROW(1, "ZSTD_createCDict() allocation failure");
|
if (cdict==NULL) EXM_THROW(1, "ZSTD_createCDict() allocation failure");
|
||||||
do {
|
do {
|
||||||
U32 blockNb;
|
U32 blockNb;
|
||||||
|
|||||||
Reference in New Issue
Block a user