-b# and -e# options from zstd

This commit is contained in:
inikep 2016-09-02 22:59:18 +02:00
parent c1864f69e8
commit 2cf32ef0f1
6 changed files with 78 additions and 40 deletions

View File

@ -150,7 +150,6 @@ static void LZ4F_writeLE64 (BYTE* dstPtr, U64 value64)
static const size_t minFHSize = 7;
static const size_t maxFHSize = 15;
static const size_t BHSize = 4;
static const int minHClevel = 3;
/*-************************************
@ -306,7 +305,7 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf
if (prefs.frameInfo.contentSize != 0)
prefs.frameInfo.contentSize = (U64)srcSize; /* auto-correct content size if selected (!=0) */
if (prefs.compressionLevel < (int)minHClevel) {
if (prefs.compressionLevel < LZ4HC_MIN_CLEVEL) {
cctxI.lz4CtxPtr = &lz4ctx;
cctxI.lz4CtxLevel = 1;
}
@ -333,7 +332,7 @@ size_t LZ4F_compressFrame(void* dstBuffer, size_t dstMaxSize, const void* srcBuf
if (LZ4F_isError(errorCode)) return errorCode;
dstPtr += errorCode;
if (prefs.compressionLevel >= (int)minHClevel) /* no allocation necessary with lz4 fast */
if (prefs.compressionLevel >= LZ4HC_MIN_CLEVEL) /* no allocation necessary with lz4 fast */
FREEMEM(cctxI.lz4CtxPtr);
return (dstPtr - dstStart);
@ -404,10 +403,10 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* ds
cctxPtr->prefs = *preferencesPtr;
/* ctx Management */
{ U32 const tableID = (cctxPtr->prefs.compressionLevel < minHClevel) ? 1 : 2; /* 0:nothing ; 1:LZ4 table ; 2:HC tables */
{ U32 const tableID = (cctxPtr->prefs.compressionLevel < LZ4HC_MIN_CLEVEL) ? 1 : 2; /* 0:nothing ; 1:LZ4 table ; 2:HC tables */
if (cctxPtr->lz4CtxLevel < tableID) {
FREEMEM(cctxPtr->lz4CtxPtr);
if (cctxPtr->prefs.compressionLevel < minHClevel)
if (cctxPtr->prefs.compressionLevel < LZ4HC_MIN_CLEVEL)
cctxPtr->lz4CtxPtr = (void*)LZ4_createStream();
else
cctxPtr->lz4CtxPtr = (void*)LZ4_createStreamHC();
@ -432,7 +431,7 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* ds
cctxPtr->tmpIn = cctxPtr->tmpBuff;
cctxPtr->tmpInSize = 0;
XXH32_reset(&(cctxPtr->xxh), 0);
if (cctxPtr->prefs.compressionLevel < minHClevel)
if (cctxPtr->prefs.compressionLevel < LZ4HC_MIN_CLEVEL)
LZ4_resetStream((LZ4_stream_t*)(cctxPtr->lz4CtxPtr));
else
LZ4_resetStreamHC((LZ4_streamHC_t*)(cctxPtr->lz4CtxPtr), cctxPtr->prefs.compressionLevel);
@ -525,7 +524,7 @@ static int LZ4F_localLZ4_compressHC_limitedOutput_continue(void* ctx, const char
static compressFunc_t LZ4F_selectCompression(LZ4F_blockMode_t blockMode, int level)
{
if (level < minHClevel) {
if (level < LZ4HC_MIN_CLEVEL) {
if (blockMode == LZ4F_blockIndependent) return LZ4F_localLZ4_compress_limitedOutput_withState;
return LZ4F_localLZ4_compress_limitedOutput_continue;
}
@ -535,7 +534,7 @@ static compressFunc_t LZ4F_selectCompression(LZ4F_blockMode_t blockMode, int lev
static int LZ4F_localSaveDict(LZ4F_cctx_t* cctxPtr)
{
if (cctxPtr->prefs.compressionLevel < minHClevel)
if (cctxPtr->prefs.compressionLevel < LZ4HC_MIN_CLEVEL)
return LZ4_saveDict ((LZ4_stream_t*)(cctxPtr->lz4CtxPtr), (char*)(cctxPtr->tmpBuff), 64 KB);
return LZ4_saveDictHC ((LZ4_streamHC_t*)(cctxPtr->lz4CtxPtr), (char*)(cctxPtr->tmpBuff), 64 KB);
}

View File

@ -37,7 +37,6 @@
/* *************************************
* Tuning Parameter
***************************************/
static const int LZ4HC_compressionLevel_default = 9;
/*!
* HEAPMODE :
@ -86,8 +85,6 @@ static const int LZ4HC_compressionLevel_default = 9;
#define OPTIMAL_ML (int)((ML_MASK-1)+MINMATCH)
static const int g_maxCompressionLevel = 16;
/**************************************
* Local Types
@ -371,8 +368,8 @@ static int LZ4HC_compress_generic (
/* init */
if (compressionLevel > g_maxCompressionLevel) compressionLevel = g_maxCompressionLevel;
if (compressionLevel < 1) compressionLevel = LZ4HC_compressionLevel_default;
if (compressionLevel > LZ4HC_MAX_CLEVEL) compressionLevel = LZ4HC_MAX_CLEVEL;
if (compressionLevel < 1) compressionLevel = LZ4HC_DEFAULT_CLEVEL;
maxNbAttempts = 1 << (compressionLevel-1);
ctx->end += inputSize;

View File

@ -45,6 +45,10 @@ extern "C" {
#include <stddef.h> /* size_t */
#define LZ4HC_MIN_CLEVEL 3
#define LZ4HC_DEFAULT_CLEVEL 9
#define LZ4HC_MAX_CLEVEL 16
/*-************************************
* Block Compression
**************************************/
@ -54,9 +58,9 @@ LZ4_compress_HC() :
Compression success is guaranteed if `dst` buffer is sized to handle worst circumstances (data not compressible)
Worst size evaluation is provided by function LZ4_compressBound() (see "lz4.h")
`srcSize` : Max supported value is LZ4_MAX_INPUT_SIZE (see "lz4.h")
`compressionLevel` : Recommended values are between 4 and 9, although any value between 0 and 16 will work.
`compressionLevel` : Recommended values are between 4 and 9, although any value between 0 and LZ4HC_MAX_CLEVEL will work.
0 means "use default value" (see lz4hc.c).
Values >16 behave the same as 16.
Values >LZ4HC_MAX_CLEVEL behave the same as 16.
@return : the number of bytes written into buffer 'dst'
or 0 if compression fails.
*/

View File

@ -201,7 +201,7 @@ static U64 BMK_GetFileSize(const char* infilename)
* Public function
**********************************************************/
int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel)
int BMK_benchLevel(const char** fileNamesTable, int nbFiles, int cLevel)
{
int fileIdx=0;
char* orig_buff;
@ -214,7 +214,7 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel)
double totald = 0.;
/* Init */
if (cLevel <= 2) cfunctionId = 0; else cfunctionId = 1;
if (cLevel < LZ4HC_MIN_CLEVEL) cfunctionId = 0; else cfunctionId = 1;
switch (cfunctionId)
{
#ifdef COMPRESSOR0
@ -228,7 +228,7 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel)
/* Loop for each file */
while (fileIdx<nbFiles) {
const char* const inFileName = fileNamesTable[fileIdx++];
const char* inFileName = fileNamesTable[fileIdx++];
FILE* const inFile = fopen( inFileName, "rb" );
U64 const inFileSize = BMK_GetFileSize(inFileName);
size_t benchedSize = BMK_findMaxMem(inFileSize * 2) / 2;
@ -280,6 +280,7 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel)
/* Fill input buffer */
DISPLAY("Loading %s... \r", inFileName);
if (strlen(inFileName)>16) inFileName += strlen(inFileName)-16; /* can only display 16 characters */
readSize = fread(orig_buff, 1, benchedSize, inFile);
fclose(inFile);
@ -308,7 +309,7 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel)
unsigned chunkNb;
/* Compression */
DISPLAY("%1i-%-14.14s : %9i ->\r", loopNb, inFileName, (int)benchedSize);
DISPLAY("%2i#%1i-%-14.14s : %9i ->\r", cLevel, loopNb, inFileName, (int)benchedSize);
{ size_t i; for (i=0; i<benchedSize; i++) compressedBuffer[i]=(char)i; } /* warmimg up memory */
clockStart = clock();
@ -326,8 +327,8 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel)
cSize=0; for (chunkNb=0; chunkNb<nbChunks; chunkNb++) cSize += chunkP[chunkNb].compressedSize;
ratio = (double)cSize/(double)benchedSize*100.;
DISPLAY("%1i-%-14.14s : %9i -> %9i (%5.2f%%),%7.1f MB/s\r",
loopNb, inFileName, (int)benchedSize, (int)cSize, ratio, (double)benchedSize / (fastestC / CLOCKS_PER_SEC) / 1000000);
DISPLAY("%2i#%1i-%-14.14s : %9i -> %9i (%5.2f%%),%7.1f MB/s\r",
cLevel, loopNb, inFileName, (int)benchedSize, (int)cSize, ratio, (double)benchedSize / (fastestC / CLOCKS_PER_SEC) / 1000000);
/* Decompression */
{ size_t i; for (i=0; i<benchedSize; i++) orig_buff[i]=0; } /* zeroing area, for CRC checking */
@ -346,8 +347,8 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel)
nbLoops += !nbLoops; /* avoid division by zero */
if ((double)clockEnd < fastestD*nbLoops) fastestD = (double)clockEnd/nbLoops;
DISPLAY("%1i-%-14.14s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s \r",
loopNb, inFileName, (int)benchedSize, (int)cSize, ratio,
DISPLAY("%2i#%1i-%-14.14s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s \r",
cLevel, loopNb, inFileName, (int)benchedSize, (int)cSize, ratio,
(double)benchedSize / (fastestC / CLOCKS_PER_SEC) / 1000000, (double)benchedSize / (fastestD / CLOCKS_PER_SEC) / 1000000 );
/* CRC Checking */
@ -357,12 +358,12 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel)
if (crcOrig==crcCheck) {
if (ratio < 100.)
DISPLAY("%-16.16s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s \n",
inFileName, (int)benchedSize, (int)cSize, ratio,
DISPLAY("%2i#%-16.16s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s \n",
cLevel, inFileName, (int)benchedSize, (int)cSize, ratio,
(double)benchedSize / (fastestC / CLOCKS_PER_SEC) / 1000000, (double)benchedSize / (fastestD / CLOCKS_PER_SEC) / 1000000 );
else
DISPLAY("%-16.16s : %9i -> %9i (%5.1f%%),%7.1f MB/s ,%7.1f MB/s \n",
inFileName, (int)benchedSize, (int)cSize, ratio,
DISPLAY("%2i#%-16.16s : %9i -> %9i (%5.1f%%),%7.1f MB/s ,%7.1f MB/s \n",
cLevel, inFileName, (int)benchedSize, (int)cSize, ratio,
(double)benchedSize / (fastestC / CLOCKS_PER_SEC) / 1000000, (double)benchedSize / (fastestD / CLOCKS_PER_SEC) / 1000000 );
}
totals += benchedSize;
@ -377,7 +378,7 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel)
}
if (nbFiles > 1)
DISPLAY("%-16.16s :%10llu ->%10llu (%5.2f%%), %6.1f MB/s , %6.1f MB/s\n", " TOTAL",
DISPLAY("%2i#%-16.16s :%10llu ->%10llu (%5.2f%%), %6.1f MB/s , %6.1f MB/s\n", cLevel, " TOTAL",
(long long unsigned)totals, (long long unsigned int)totalz, (double)totalz/(double)totals*100.,
(double)totals/(totalc/CLOCKS_PER_SEC)/1000000, (double)totals/(totald/CLOCKS_PER_SEC)/1000000);
@ -385,3 +386,21 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel)
return 0;
}
int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel, int cLevelLast)
{
int i, res = 0;
if (cLevel > LZ4HC_MAX_CLEVEL) cLevel = LZ4HC_MAX_CLEVEL;
if (cLevelLast > LZ4HC_MAX_CLEVEL) cLevelLast = LZ4HC_MAX_CLEVEL;
if (cLevelLast < cLevel) cLevelLast = cLevel;
DISPLAY("Benchmarking levels from %d to %d\n", cLevel, cLevelLast);
for (i=cLevel; i<=cLevelLast; i++) {
res = BMK_benchLevel(fileNamesTable, nbFiles, i);
if (res != 0) break;
}
return res;
}

View File

@ -24,7 +24,8 @@
/* Main function */
int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel);
int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel, int cLevelLast);
int BMK_benchLevel(const char** fileNamesTable, int nbFiles, int cLevel);
/* Set Parameters */
void BMK_setBlocksize(int bsize);

View File

@ -61,7 +61,7 @@
#include <string.h> /* strcmp, strlen */
#include "bench.h" /* BMK_benchFile, BMK_SetNbIterations, BMK_SetBlocksize, BMK_SetPause */
#include "lz4io.h" /* LZ4IO_compressFilename, LZ4IO_decompressFilename, LZ4IO_compressMultipleFilenames */
#include "lz4hc.h" /* LZ4HC_DEFAULT_CLEVEL */
/****************************
* OS-specific Includes
@ -183,7 +183,9 @@ static int usage_advanced(void)
DISPLAY( "--content-size : compressed frame includes original size (default:not present)\n");
DISPLAY( "--[no-]sparse : sparse mode (default:enabled on file, disabled on stdout)\n");
DISPLAY( "Benchmark arguments :\n");
DISPLAY( " -b : benchmark file(s)\n");
DISPLAY( "Benchmark arguments :\n");
DISPLAY( " -b# : benchmark file(s), using # compression level (default : 1) \n");
DISPLAY( " -e# : test all compression levels from -bX to # (default: 1)\n");
DISPLAY( " -i# : iteration loops [1-9](default : 3), benchmark mode only\n");
#if defined(ENABLE_LZ4C_LEGACY_OPTIONS)
DISPLAY( "Legacy arguments :\n");
@ -219,7 +221,7 @@ static int usage_longhelp(void)
DISPLAY( "Compression levels : \n");
DISPLAY( "---------------------\n");
DISPLAY( "-0 ... -2 => Fast compression, all identicals\n");
DISPLAY( "-3 ... -16 => High compression; higher number == more compression but slower\n");
DISPLAY( "-3 ... -%d => High compression; higher number == more compression but slower\n", LZ4HC_MAX_CLEVEL);
DISPLAY( "\n");
DISPLAY( "stdin, stdout and the console : \n");
DISPLAY( "--------------------------------\n");
@ -272,10 +274,24 @@ static void waitEnter(void)
}
/*! readU32FromChar() :
@return : unsigned integer value reach from input in `char` format
Will also modify `*stringPtr`, advancing it to position where it stopped reading.
Note : this function can overflow if result > MAX_UINT */
static unsigned readU32FromChar(const char** stringPtr)
{
unsigned result = 0;
while ((**stringPtr >='0') && (**stringPtr <='9'))
result *= 10, result += **stringPtr - '0', (*stringPtr)++ ;
return result;
}
int main(int argc, const char** argv)
{
int i,
cLevel=0,
cLevel=1,
cLevelLast=1,
decode=0,
bench=0,
legacy_format=0,
@ -350,16 +366,12 @@ int main(int argc, const char** argv)
#endif /* ENABLE_LZ4C_LEGACY_OPTIONS */
if ((*argument>='0') && (*argument<='9')) {
cLevel = 0;
while ((*argument >= '0') && (*argument <= '9')) {
cLevel *= 10;
cLevel += *argument - '0';
argument++;
}
cLevel = readU32FromChar(&argument);
argument--;
continue;
}
switch(argument[0])
{
/* Display help */
@ -367,6 +379,12 @@ int main(int argc, const char** argv)
case 'h': usage_advanced(); goto _cleanup;
case 'H': usage_longhelp(); goto _cleanup;
case 'e':
argument++;
cLevelLast = readU32FromChar(&argument);
argument--;
break;
/* Compression (default) */
case 'z': forceCompress = 1; break;
@ -492,7 +510,7 @@ int main(int argc, const char** argv)
/* Check if benchmark is selected */
if (bench)
{
int bmkResult = BMK_benchFiles(inFileNames, ifnIdx, cLevel);
int bmkResult = BMK_benchFiles(inFileNames, ifnIdx, cLevel, cLevelLast);
free((void*)inFileNames);
return bmkResult;
}