Merge branch 'makefile' into fasterfbench

This commit is contained in:
Yann Collet 2023-12-25 11:37:50 -08:00
commit d7674fad29

View File

@ -179,6 +179,13 @@ static void local_LZ4_createStream(void)
assert(r != NULL); (void)r;
}
static void* g_chunk0 = NULL;
static size_t g_chunk0Size = 0;
static void local_LZ4_saveDict_init(void)
{
LZ4_loadDict(&LZ4_stream, g_chunk0, (int)g_chunk0Size);
}
static int local_LZ4_saveDict(const char* in, char* out, int inSize)
{
(void)in;
@ -256,6 +263,11 @@ static void local_LZ4_resetStreamHC(void)
LZ4_initStreamHC(&LZ4_streamHC, sizeof(LZ4_streamHC));
}
static void local_LZ4_saveDictHC_init(void)
{
LZ4_loadDictHC(&LZ4_streamHC, g_chunk0, (int)g_chunk0Size);
}
static int local_LZ4_saveDictHC(const char* in, char* out, int inSize)
{
(void)in;
@ -481,8 +493,68 @@ static int local_LZ4F_decompress_noHint(const char* src, char* dst, int srcSize,
}
#define NB_COMPRESSION_ALGORITHMS 100
#define NB_DECOMPRESSION_ALGORITHMS 100
typedef struct {
const char* name;
int (*compressionF)(const char*, char*, int);
void (*initFunction)(void);
int singleChunk;
} CompressionDesc;
const CompressionDesc compDescArray[] = {
{ NULL, NULL, NULL, 0 },
{ "LZ4_compress_default", local_LZ4_compress_default_large, NULL, 0 },
{ "LZ4_compress_default(small dst)", local_LZ4_compress_default_small, NULL, 0 },
{ "LZ4_compress_destSize", local_LZ4_compress_destSize, NULL, 0 },
{ "LZ4_compress_fast(0)", local_LZ4_compress_fast0, NULL, 0 },
{ "LZ4_compress_fast(1)", local_LZ4_compress_fast1, NULL, 0 },
{ "LZ4_compress_fast(2)", local_LZ4_compress_fast2, NULL, 0 },
{ "LZ4_compress_fast(17)", local_LZ4_compress_fast17, NULL, 0 },
{ "LZ4_compress_fast_extState(0)", local_LZ4_compress_fast_extState0, NULL, 0 },
{ "LZ4_compress_fast_continue(0)", local_LZ4_compress_fast_continue0, local_LZ4_createStream, 0 },
{ "LZ4_compress_HC", local_LZ4_compress_HC, NULL, 0 },
{ "LZ4_compress_HC_extStateHC", local_LZ4_compress_HC_extStateHC, NULL, 0 },
{ "LZ4_compress_HC_continue", local_LZ4_compress_HC_continue, local_LZ4_resetStreamHC, 0 },
#ifndef LZ4_DLL_IMPORT
{ "LZ4_compress_forceDict", local_LZ4_compress_forceDict, local_LZ4_resetDictT, 0 },
#endif
{ "LZ4F_compressFrame", local_LZ4F_compressFrame, NULL, 1 },
{ "LZ4F_compressUpdate", local_LZ4F_compress, NULL, 1 },
{ "LZ4_saveDict", local_LZ4_saveDict, local_LZ4_saveDict_init, 0 },
{ "LZ4_saveDictHC", local_LZ4_saveDictHC, local_LZ4_saveDictHC_init, 0 },
};
typedef struct {
const char* name;
int (*decompressionF)(const char*, char*, int, int);
int checkResult;
int frameFormat;
} DecompressionDesc;
const DecompressionDesc decDescArray[] = {
{ NULL, NULL, 0, 0 },
{ "LZ4_decompress_fast", local_LZ4_decompress_fast, 1, 0 },
{ "LZ4_decompress_fast_usingDict(prefix)", local_LZ4_decompress_fast_usingDict_prefix, 1, 0 },
{ "LZ4_decompress_fast_using(Ext)Dict", local_LZ4_decompress_fast_usingExtDict, 1, 0 },
{ "LZ4_decompress_safe", LZ4_decompress_safe, 1, 0 },
{ "LZ4_decompress_safe_withPrefix64k", local_LZ4_decompress_safe_withPrefix64k, 1, 0 },
{ "LZ4_decompress_safe_usingDict", local_LZ4_decompress_safe_usingDict, 1, 0 },
{ "LZ4_decompress_safe_partial", local_LZ4_decompress_safe_partial, 0, 0 },
{ "LZ4_decompress_safe_partial_usingDict", local_LZ4_decompress_safe_partial_usingDict, 0, 0 },
#ifndef LZ4_DLL_IMPORT
{ "LZ4_decompress_safe_partial_forceExtDict", local_LZ4_decompress_safe_partial_forceExtDict, 0, 0 },
{ "LZ4_decompress_safe_forceExtDict", local_LZ4_decompress_safe_forceExtDict, 1, 0 },
#endif
{ "LZ4F_decompress", local_LZ4F_decompress, 1, 1 },
{ "LZ4F_decompLZ4F_decompress_followHintress", local_LZ4F_decompress_followHint, 1, 1 },
{ "LZ4F_decompress_noHint", local_LZ4F_decompress_noHint, 1, 1 },
};
#define ARRAY_SIZE(a) (sizeof(a) / (sizeof((a)[0])))
#define NB_COMPRESSION_ALGORITHMS ARRAY_SIZE(compDescArray)
#define NB_DECOMPRESSION_ALGORITHMS ARRAY_SIZE(decDescArray)
int fullSpeedBench(const char** fileNamesTable, int nbFiles)
{
int fileIdx=0;
@ -517,11 +589,15 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
DISPLAY("Not enough memory for '%s' full size; testing %i MB only... \n",
inFileName, (int)(benchedSize>>20));
}
if (benchedSize < 8 || g_chunkSize < 8) {
DISPLAY(" cannot bench using less then 8 bytes \n");
return 1;
}
/* Allocation */
chunkP = (struct chunkParameters*) malloc(((benchedSize / (size_t)g_chunkSize)+1) * sizeof(struct chunkParameters));
orig_buff = (char*) malloc(benchedSize);
nbChunks = (int) ((benchedSize + (size_t)g_chunkSize - 1) / (size_t)g_chunkSize);
chunkP = (struct chunkParameters*) malloc((size_t)nbChunks * sizeof(chunkP[0]));
orig_buff = (char*) malloc(benchedSize);
maxCompressedChunkSize = LZ4_compressBound(g_chunkSize);
compressedBuffSize = nbChunks * maxCompressedChunkSize;
compressed_buff = (char*)malloc((size_t)compressedBuffSize);
@ -550,7 +626,6 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
/* Calculating input Checksum */
crcOriginal = XXH32(orig_buff, benchedSize,0);
/* Bench */
{ int loopNb, nb_loops, chunkNb, cAlgNb, dAlgNb;
size_t cSize=0;
@ -560,7 +635,7 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
DISPLAY(" %s : \n", inFileName);
/* Bench Compression Algorithms */
for (cAlgNb=0; (cAlgNb <= NB_COMPRESSION_ALGORITHMS) && (g_compressionTest); cAlgNb++) {
for (cAlgNb=0; (cAlgNb <= (int)NB_COMPRESSION_ALGORITHMS) && (g_compressionTest); cAlgNb++) {
const char* compressorName;
int (*compressionFunction)(const char*, char*, int);
void (*initFunction)(void) = NULL;
@ -590,42 +665,25 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
chunkP[i].compressedSize = 0;
}
}
g_chunk0 = chunkP[0].origBuffer;
g_chunk0Size = (size_t)chunkP[0].origSize;
switch(cAlgNb)
{
case 0 : DISPLAY("Compression functions : \n"); continue;
case 1 : compressionFunction = local_LZ4_compress_default_large; compressorName = "LZ4_compress_default"; break;
case 2 : compressionFunction = local_LZ4_compress_default_small; compressorName = "LZ4_compress_default(small dst)"; break;
case 3 : compressionFunction = local_LZ4_compress_destSize; compressorName = "LZ4_compress_destSize"; break;
case 4 : compressionFunction = local_LZ4_compress_fast0; compressorName = "LZ4_compress_fast(0)"; break;
case 5 : compressionFunction = local_LZ4_compress_fast1; compressorName = "LZ4_compress_fast(1)"; break;
case 6 : compressionFunction = local_LZ4_compress_fast2; compressorName = "LZ4_compress_fast(2)"; break;
case 7 : compressionFunction = local_LZ4_compress_fast17; compressorName = "LZ4_compress_fast(17)"; break;
case 8 : compressionFunction = local_LZ4_compress_fast_extState0; compressorName = "LZ4_compress_fast_extState(0)"; break;
case 9 : compressionFunction = local_LZ4_compress_fast_continue0; initFunction = local_LZ4_createStream; compressorName = "LZ4_compress_fast_continue(0)"; break;
case 10: compressionFunction = local_LZ4_compress_HC; compressorName = "LZ4_compress_HC"; break;
case 12: compressionFunction = local_LZ4_compress_HC_extStateHC; compressorName = "LZ4_compress_HC_extStateHC"; break;
case 14: compressionFunction = local_LZ4_compress_HC_continue; initFunction = local_LZ4_resetStreamHC; compressorName = "LZ4_compress_HC_continue"; break;
#ifndef LZ4_DLL_IMPORT
case 20: compressionFunction = local_LZ4_compress_forceDict; initFunction = local_LZ4_resetDictT; compressorName = "LZ4_compress_forceDict"; break;
#endif
case 30: compressionFunction = local_LZ4F_compressFrame; compressorName = "LZ4F_compressFrame";
chunkP[0].origSize = (int)benchedSize; nbChunks=1;
break;
case 31: compressionFunction = local_LZ4F_compress; compressorName = "LZ4F_compressUpdate";
chunkP[0].origSize = (int)benchedSize; nbChunks=1;
break;
case 40: compressionFunction = local_LZ4_saveDict; compressorName = "LZ4_saveDict";
if (chunkP[0].origSize < 8) { DISPLAY(" cannot bench %s with less then 8 bytes \n", compressorName); continue; }
LZ4_loadDict(&LZ4_stream, chunkP[0].origBuffer, chunkP[0].origSize);
break;
case 41: compressionFunction = local_LZ4_saveDictHC; compressorName = "LZ4_saveDictHC";
if (chunkP[0].origSize < 8) { DISPLAY(" cannot bench %s with less then 8 bytes \n", compressorName); continue; }
LZ4_loadDictHC(&LZ4_streamHC, chunkP[0].origBuffer, chunkP[0].origSize);
break;
default :
continue; /* unknown ID : just skip */
if (cAlgNb==0) {
DISPLAY("Compression functions : \n");
continue;
}
if (cAlgNb > (int)NB_COMPRESSION_ALGORITHMS) {
continue;
}
compressorName = compDescArray[cAlgNb].name;
compressionFunction = compDescArray[cAlgNb].compressionF;
initFunction = compDescArray[cAlgNb].initFunction;
if (compDescArray[cAlgNb].singleChunk) {
nbChunks=1;
chunkP[0].origSize = (int)benchedSize;
}
if (compressorName==NULL || compressionFunction==NULL) {
continue;
}
for (loopNb = 1; loopNb <= g_nbIterations; loopNb++) {
@ -695,7 +753,7 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
} }
/* Decompression Algorithms */
for (dAlgNb=0; (dAlgNb <= NB_DECOMPRESSION_ALGORITHMS) && g_decompressionTest; dAlgNb++) {
for (dAlgNb=0; (dAlgNb <= (int)NB_DECOMPRESSION_ALGORITHMS) && g_decompressionTest; dAlgNb++) {
const char* dName = NULL;
int (*decompressionFunction)(const char*, char*, int, int) = NULL;
double bestTime = 100000000.;
@ -703,41 +761,25 @@ int fullSpeedBench(const char** fileNamesTable, int nbFiles)
if ((g_decompressionAlgo != ALL_DECOMPRESSORS) && (g_decompressionAlgo != dAlgNb)) continue;
switch(dAlgNb)
{
case 0: DISPLAY("Decompression functions : \n"); continue;
case 1: decompressionFunction = local_LZ4_decompress_fast; dName = "LZ4_decompress_fast"; break;
case 2: decompressionFunction = local_LZ4_decompress_fast_usingDict_prefix; dName = "LZ4_decompress_fast_usingDict(prefix)"; break;
case 3: decompressionFunction = local_LZ4_decompress_fast_usingExtDict; dName = "LZ4_decompress_fast_using(Ext)Dict"; break;
case 4: decompressionFunction = LZ4_decompress_safe; dName = "LZ4_decompress_safe"; break;
case 5: decompressionFunction = local_LZ4_decompress_safe_withPrefix64k; dName = "LZ4_decompress_safe_withPrefix64k"; break;
case 6: decompressionFunction = local_LZ4_decompress_safe_usingDict; dName = "LZ4_decompress_safe_usingDict"; break;
case 7: decompressionFunction = local_LZ4_decompress_safe_partial; dName = "LZ4_decompress_safe_partial"; checkResult = 0; break;
case 8: decompressionFunction = local_LZ4_decompress_safe_partial_usingDict; dName = "LZ4_decompress_safe_partial_usingDict"; checkResult = 0; break;
#ifndef LZ4_DLL_IMPORT
case 9: decompressionFunction = local_LZ4_decompress_safe_partial_forceExtDict; dName = "LZ4_decompress_safe_partial_forceExtDict"; checkResult = 0; break;
case 10: decompressionFunction = local_LZ4_decompress_safe_forceExtDict; dName = "LZ4_decompress_safe_forceExtDict"; break;
#endif
case 11:
case 12:
case 13:
if (dAlgNb == 11) { decompressionFunction = local_LZ4F_decompress; dName = "LZ4F_decompress"; } /* can be skipped */
if (dAlgNb == 12) { decompressionFunction = local_LZ4F_decompress_followHint; dName = "LZ4F_decompress_followHint"; } /* can be skipped */
if (dAlgNb == 13) { decompressionFunction = local_LZ4F_decompress_noHint; dName = "LZ4F_decompress_noHint"; } /* can be skipped */
/* prepare compressed data using frame format */
{ size_t const fcsize = LZ4F_compressFrame(compressed_buff, (size_t)compressedBuffSize, orig_buff, benchedSize, NULL);
assert(!LZ4F_isError(fcsize));
chunkP[0].origSize = (int)benchedSize;
chunkP[0].compressedSize = (int)fcsize;
nbChunks = 1;
break;
}
default :
continue; /* skip if unknown ID */
if (dAlgNb==0) { /* just for display */
DISPLAY("Decompression functions : \n");
continue;
}
if (dAlgNb >= (int)NB_DECOMPRESSION_ALGORITHMS)
continue;
dName = decDescArray[dAlgNb].name;
decompressionFunction = decDescArray[dAlgNb].decompressionF;
if (dName==NULL || decompressionFunction == NULL)
continue;
checkResult = decDescArray[dAlgNb].checkResult;
if (decDescArray[dAlgNb].frameFormat) {
/* prepare compressed data using LZ4F frame format */
size_t const fcsize = LZ4F_compressFrame(compressed_buff, (size_t)compressedBuffSize, orig_buff, benchedSize, NULL);
assert(!LZ4F_isError(fcsize));
chunkP[0].origSize = (int)benchedSize;
chunkP[0].compressedSize = (int)fcsize;
nbChunks = 1;
}
assert(decompressionFunction != NULL);
assert(dName != NULL);
{ size_t i; for (i=0; i<benchedSize; i++) orig_buff[i]=0; } /* zeroing source area, for CRC checking */
@ -808,8 +850,8 @@ static int usage(const char* exename)
static int usage_advanced(void)
{
DISPLAY( "\nAdvanced options :\n");
DISPLAY( " -c# : test only compression function # [1-%i]\n", NB_COMPRESSION_ALGORITHMS);
DISPLAY( " -d# : test only decompression function # [1-%i]\n", NB_DECOMPRESSION_ALGORITHMS);
DISPLAY( " -c# : test only compression function # [1-%i]\n", (int)NB_COMPRESSION_ALGORITHMS);
DISPLAY( " -d# : test only decompression function # [1-%i]\n", (int)NB_DECOMPRESSION_ALGORITHMS);
DISPLAY( " -i# : iteration loops [1-9](default : %i)\n", NBLOOPS);
DISPLAY( " -B# : Block size [4-7](default : 7)\n");
return 0;