27 #if defined(_MSC_VER) || defined(_WIN32)
29 # define BMK_LEGACY_TIMER 1
40 #include <sys/types.h>
45 #define LZ4_DISABLE_DEPRECATE_WARNINGS
56 #define PROGRAM_DESCRIPTION "LZ4 speed analyzer"
57 #define AUTHOR "Yann Collet"
58 #define WELCOME_MESSAGE "*** %s v%s %i-bits, by %s ***\n", PROGRAM_DESCRIPTION, LZ4_VERSION_STRING, (int)(sizeof(void*)*8), AUTHOR
61 #define TIMELOOP (CLOCKS_PER_SEC * 25 / 10)
67 #define KNUTH 2654435761U
68 #define MAX_MEM (1920 MB)
69 #define DEFAULT_CHUNKSIZE (4 MB)
71 #define ALL_COMPRESSORS 0
72 #define ALL_DECOMPRESSORS 0
91 #define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
92 #define PROGRESS(...) g_noPrompt ? 0 : DISPLAY(__VA_ARGS__)
130 return clock() - clockStart;
139 requiredMem = (((requiredMem >> 26) + 1) << 26);
140 requiredMem += 2*
step;
144 if (requiredMem >
step) requiredMem -=
step;
145 else requiredMem >>= 1;
146 testmem = (
BYTE*)
malloc ((
size_t)requiredMem);
151 if (requiredMem >
step) requiredMem -=
step;
152 else requiredMem >>= 1;
154 return (
size_t)requiredMem;
233 #ifndef LZ4_DLL_IMPORT
234 #if defined (__cplusplus)
241 #if defined (__cplusplus)
315 #ifndef LZ4_DLL_IMPORT
316 #if defined (__cplusplus)
322 #if defined (__cplusplus)
337 if (result < 0)
return result;
354 size_t dstSize = (
size_t)outSize;
359 if (result!=0) {
DISPLAY(
"Error decompressing frame : unfinished frame \n");
exit(8); }
360 if (
srcSize != (
size_t)inSize) {
DISPLAY(
"Error decompressing frame : read size incorrect \n");
exit(9); }
367 size_t maxOutSize = (
size_t)dstSize;
372 size_t outRemaining = maxOutSize - outPos;
381 outPos += outRemaining;
382 outRemaining = maxOutSize - outPos;
384 if (!sizeHint)
break;
388 if (inPos != totalInSize) {
389 DISPLAY(
"Error decompressing frame : must read (%u) full frame (%u) \n",
390 (
unsigned)inPos, (
unsigned)totalInSize);
401 size_t maxOutSize = (
size_t)dstSize;
404 size_t inSize = 64
KB;
406 size_t outRemaining = maxOutSize - outPos;
413 inSize = (inPos + 64
KB <= totalInSize) ? 64
KB : totalInSize - inPos;
415 outPos += outRemaining;
416 outRemaining = maxOutSize - outPos;
418 if (!sizeHint)
break;
422 if (inPos != totalInSize) {
423 DISPLAY(
"Error decompressing frame : must read (%u) full frame (%u) \n",
424 (
unsigned)inPos, (
unsigned)totalInSize);
431 #define NB_COMPRESSION_ALGORITHMS 100
432 #define NB_DECOMPRESSION_ALGORITHMS 100
442 while (fileIdx<nbFiles) {
443 char* orig_buff =
NULL;
445 char* compressed_buff=
NULL;
446 const char*
const inFileName = fileNamesTable[fileIdx++];
447 FILE*
const inFile = fopen( inFileName,
"rb" );
451 int maxCompressedChunkSize;
453 int compressedBuffSize;
457 if (inFile==
NULL) {
DISPLAY(
"Pb opening %s \n", inFileName);
return 11; }
458 if (inFileSize==0) {
DISPLAY(
"file is empty \n"); fclose(inFile);
return 11; }
459 if (benchedSize==0) {
DISPLAY(
"not enough memory \n"); fclose(inFile);
return 11; }
462 if ((
U64)benchedSize > inFileSize) benchedSize = (
size_t)inFileSize;
463 if (benchedSize < inFileSize) {
464 DISPLAY(
"Not enough memory for '%s' full size; testing %i MB only... \n",
465 inFileName, (
int)(benchedSize>>20));
470 orig_buff = (
char*)
malloc(benchedSize);
473 compressedBuffSize = nbChunks * maxCompressedChunkSize;
474 compressed_buff = (
char*)
malloc((
size_t)compressedBuffSize);
475 if(!chunkP || !orig_buff || !compressed_buff) {
476 DISPLAY(
"\nError: not enough memory! \n");
479 free(compressed_buff);
485 DISPLAY(
"Loading %s... \r", inFileName);
486 readSize = fread(orig_buff, 1, benchedSize, inFile);
489 if (readSize != benchedSize) {
490 DISPLAY(
"\nError: problem reading file '%s' !! \n", inFileName);
492 free(compressed_buff);
498 crcOriginal =
XXH32(orig_buff, benchedSize,0);
502 {
int loopNb, nb_loops, chunkNb, cAlgNb, dAlgNb;
507 DISPLAY(
" %s : \n", inFileName);
511 const char* compressorName;
512 int (*compressionFunction)(
const char*,
char*,
int);
513 void (*initFunction)(void) =
NULL;
514 double bestTime = 100000000.;
521 size_t remaining = benchedSize;
522 char*
in = orig_buff;
523 char*
out = compressed_buff;
525 for (
i=0;
i<nbChunks;
i++) {
543 case 0 :
DISPLAY(
"Compression functions : \n");
continue;
557 #ifndef LZ4_DLL_IMPORT
564 if (chunkP[0].
origSize < 8) {
DISPLAY(
" cannot bench %s with less then 8 bytes \n", compressorName);
continue; }
568 if (chunkP[0].
origSize < 8) {
DISPLAY(
" cannot bench %s with less then 8 bytes \n", compressorName);
continue; }
579 PROGRESS(
"%2i-%-34.34s :%10i ->\r", loopNb, compressorName, (
int)benchedSize);
580 {
size_t i;
for (
i=0;
i<benchedSize;
i++) compressed_buff[
i]=(
char)
i; }
584 while(clock() == clockTime);
587 if (initFunction!=
NULL) initFunction();
588 for (chunkNb=0; chunkNb<nbChunks; chunkNb++) {
591 DISPLAY(
"ERROR ! %s() = 0 !! \n", compressorName);
598 nb_loops += !nb_loops;
599 averageTime = ((double)clockTime) / nb_loops / CLOCKS_PER_SEC;
600 if (averageTime < bestTime) bestTime = averageTime;
601 cSize=0;
for (chunkNb=0; chunkNb<nbChunks; chunkNb++) cSize += (
size_t)chunkP[chunkNb].
compressedSize;
602 ratio = (double)cSize/(
double)benchedSize*100.;
603 PROGRESS(
"%2i-%-34.34s :%10i ->%9i (%5.2f%%),%7.1f MB/s\r", loopNb, compressorName, (
int)benchedSize, (
int)cSize, ratio, (
double)benchedSize / bestTime / 1000000);
607 DISPLAY(
"%2i-%-34.34s :%10i ->%9i (%5.2f%%),%7.1f MB/s\n", cAlgNb, compressorName, (
int)benchedSize, (
int)cSize, ratio, (
double)benchedSize / bestTime / 1000000);
609 DISPLAY(
"%2i-%-34.34s :%10i ->%9i (%5.1f%%),%7.1f MB/s\n", cAlgNb, compressorName, (
int)benchedSize, (
int)cSize, ratio, (
double)benchedSize / bestTime / 100000);
615 size_t remaining = benchedSize;
616 char*
in = orig_buff;
617 char*
out = compressed_buff;
620 for (
i=0;
i<nbChunks;
i++) {
634 for (chunkNb=0; chunkNb<nbChunks; chunkNb++) {
637 DISPLAY(
"ERROR ! %s() = 0 !! \n",
"LZ4_compress");
643 const char* dName =
NULL;
644 int (*decompressionFunction)(
const char*,
char*,
int,
int) =
NULL;
645 double bestTime = 100000000.;
652 case 0:
DISPLAY(
"Decompression functions : \n");
continue;
660 #ifndef LZ4_DLL_IMPORT
670 {
size_t const fcsize =
LZ4F_compressFrame(compressed_buff, (
size_t)compressedBuffSize, orig_buff, benchedSize,
NULL);
684 {
size_t i;
for (
i=0;
i<benchedSize;
i++) orig_buff[
i]=0; }
691 PROGRESS(
"%2i-%-34.34s :%10i ->\r", loopNb, dName, (
int)benchedSize);
695 while(clock() == clockTime);
698 for (chunkNb=0; chunkNb<nbChunks; chunkNb++) {
701 if (chunkP[chunkNb].
origSize != decodedSize) {
702 DISPLAY(
"ERROR ! %s() == %i != %i !! \n",
703 dName, decodedSize, chunkP[chunkNb].
origSize);
710 nb_loops += !nb_loops;
711 averageTime = (double)clockTime / nb_loops / CLOCKS_PER_SEC;
712 if (averageTime < bestTime) bestTime = averageTime;
714 PROGRESS(
"%2i-%-34.34s :%10i -> %7.1f MB/s\r", loopNb, dName, (
int)benchedSize, (
double)benchedSize / bestTime / 1000000);
717 crcDecoded =
XXH32(orig_buff, benchedSize, 0);
718 if (checkResult && (crcOriginal!=crcDecoded)) {
719 DISPLAY(
"\n!!! WARNING !!! %14s : Invalid Checksum : %x != %x\n",
720 inFileName, (
unsigned)crcOriginal, (
unsigned)crcDecoded);
724 DISPLAY(
"%2i-%-34.34s :%10i -> %7.1f MB/s\n", dAlgNb, dName, (
int)benchedSize, (
double)benchedSize / bestTime / 1000000);
728 free(compressed_buff);
733 if (
g_pause) {
printf(
"press enter...\n"); (void)getchar(); }
739 static int usage(
const char* exename)
742 DISPLAY(
" %s [arg] file1 file2 ... fileX\n", exename);
744 DISPLAY(
" -c : compression tests only\n");
745 DISPLAY(
" -d : decompression tests only\n");
746 DISPLAY(
" -H/-h : Help (this text + advanced options)\n");
752 DISPLAY(
"\nAdvanced options :\n");
755 DISPLAY(
" -i# : iteration loops [1-9](default : %i)\n",
NBLOOPS);
756 DISPLAY(
" -B# : Block size [4-7](default : 7)\n");
771 const char* exename =
argv[0];
772 const char* input_filename=0;
777 if (argc<2) {
badusage(exename);
return 1; }
779 for(
i=1;
i<argc;
i++) {
780 const char* argument =
argv[
i];
782 if(!argument)
continue;
783 if (!strcmp(argument,
"--no-prompt")) {
789 if (argument[0]==
'-') {
790 while (argument[1]!=0) {
798 while ((argument[1]>=
'0') && (argument[1]<=
'9')) {
808 while ((argument[1]>=
'0') && (argument[1]<=
'9')) {
821 while (argument[1]!=0)
828 {
int B = argument[1] -
'0';
829 int S = 1 << (8 + 2*
B);
834 case 'D': argument++;
break;
835 default :
goto _exit_blockProperties;
837 _exit_blockProperties:
842 if ((argument[1] >=
'0') && (argument[1] <=
'9')) {
843 int iters = argument[1] -
'0';
860 if (!input_filename) { input_filename=argument; filenamesStart=
i;
continue; }
865 if(!input_filename) {
badusage(exename);
return 1; }
const lzma_allocator const uint8_t * in
const lzma_allocator const uint8_t size_t uint8_t * out
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
static states step(struct re_guts *, sopno, sopno, states, int, states)
static int local_LZ4_compress_fast2(const char *in, char *out, int inSize)
static void BMK_setPause(void)
#define NB_DECOMPRESSION_ALGORITHMS
static int local_LZ4F_compressFrame(const char *in, char *out, int inSize)
static int local_LZ4_decompress_fast_usingDict_prefix(const char *in, char *out, int inSize, int outSize)
static int g_decompressionAlgo
static int local_LZ4_decompress_fast_usingExtDict(const char *in, char *out, int inSize, int outSize)
LZ4_streamHC_t LZ4_streamHC
int main(int argc, const char **argv)
static int local_LZ4_compress_fast0(const char *in, char *out, int inSize)
static int local_LZ4F_decompress(const char *in, char *out, int inSize, int outSize)
static int local_LZ4_compress_HC(const char *in, char *out, int inSize)
static int g_decompressionTest
static int local_LZ4_compress_fast_extState0(const char *in, char *out, int inSize)
static int local_LZ4_compress_default_large(const char *in, char *out, int inSize)
#define ALL_DECOMPRESSORS
static void BMK_setNbIterations(int nbLoops)
#define DEFAULT_CHUNKSIZE
static int local_LZ4_compress_destSize(const char *in, char *out, int inSize)
static clock_t BMK_GetClockSpan(clock_t clockStart)
void * LZ4_calloc(size_t n, size_t s)
static int local_LZ4_compress_HC_extStateHC(const char *in, char *out, int inSize)
static int local_LZ4_decompress_safe_withPrefix64k(const char *in, char *out, int inSize, int outSize)
static int local_LZ4_decompress_safe_forceExtDict(const char *in, char *out, int inSize, int outSize)
static int local_LZ4_compress_fast17(const char *in, char *out, int inSize)
static int usage(const char *exename)
static void BMK_setBlocksize(int bsize)
static int local_LZ4_saveDictHC(const char *in, char *out, int inSize)
static size_t BMK_findMaxMem(U64 requiredMem)
static int local_LZ4_compress_fast1(const char *in, char *out, int inSize)
static int g_compressionAlgo
static int local_LZ4_decompress_safe_partial(const char *in, char *out, int inSize, int outSize)
static int local_LZ4F_decompress_followHint(const char *src, char *dst, int srcSize, int dstSize)
int fullSpeedBench(const char **fileNamesTable, int nbFiles)
static int badusage(const char *exename)
static int g_compressionTest
static void local_LZ4_resetDictT(void)
static int local_LZ4F_decompress_noHint(const char *src, char *dst, int srcSize, int dstSize)
void * LZ4_malloc(size_t s)
static void local_LZ4_resetStreamHC(void)
static int local_LZ4_compress_fast_continue0(const char *in, char *out, int inSize)
static int local_LZ4_compress_forceDict(const char *in, char *out, int inSize)
static int local_LZ4_decompress_safe_usingDict(const char *in, char *out, int inSize, int outSize)
static int local_LZ4_compress_HC_continue(const char *in, char *out, int inSize)
static int local_LZ4_compress_default_small(const char *in, char *out, int inSize)
int LZ4_compress_forceExtDict(LZ4_stream_t *LZ4_stream, const char *source, char *dest, int inputSize)
static int local_LZ4_saveDict(const char *in, char *out, int inSize)
static int local_LZ4_decompress_fast(const char *in, char *out, int inSize, int outSize)
static LZ4F_decompressionContext_t g_dCtx
static int g_nbIterations
static void local_LZ4_createStream(void)
static LZ4_stream_t LZ4_stream
int LZ4_decompress_safe_forceExtDict(const char *in, char *out, int inSize, int outSize, const void *dict, size_t dictSize)
static int usage_advanced(void)
#define NB_COMPRESSION_ALGORITHMS
RZ_API void Ht_() free(HtName_(Ht) *ht)
void * malloc(size_t size)
void * calloc(size_t number, size_t size)
static static fork const void static count static fd const char const char static newpath char char argv
XXH_PUBLIC_API unsigned int XXH32(const void *input, size_t len, unsigned int seed)
UTIL_STATIC U64 UTIL_getFileSize(const char *infilename)
int LZ4_compress_fast_extState(void *state, const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
int LZ4_decompress_fast_usingDict(const char *source, char *dest, int originalSize, const char *dictStart, int dictSize)
int LZ4_compressBound(int isize)
int LZ4_loadDict(LZ4_stream_t *LZ4_dict, const char *dictionary, int dictSize)
LZ4_FORCE_O2 int LZ4_decompress_safe_withPrefix64k(const char *source, char *dest, int compressedSize, int maxOutputSize)
int LZ4_decompress_safe_usingDict(const char *source, char *dest, int compressedSize, int maxOutputSize, const char *dictStart, int dictSize)
LZ4_stream_t * LZ4_initStream(void *buffer, size_t size)
int LZ4_compress_default(const char *src, char *dst, int srcSize, int maxOutputSize)
int LZ4_compress_destSize(const char *src, char *dst, int *srcSizePtr, int targetDstSize)
int LZ4_compress_fast(const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
LZ4_FORCE_O2 int LZ4_decompress_fast(const char *source, char *dest, int originalSize)
LZ4_FORCE_O2 int LZ4_decompress_safe_partial(const char *src, char *dst, int compressedSize, int targetOutputSize, int dstCapacity)
int LZ4_saveDict(LZ4_stream_t *LZ4_dict, char *safeBuffer, int dictSize)
int LZ4_compress_fast_continue(LZ4_stream_t *LZ4_stream, const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
LZ4_FORCE_O2 int LZ4_decompress_safe(const char *source, char *dest, int compressedSize, int maxDecompressedSize)
const char char int inputSize
LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_dctx *dctx)
size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t *preferencesPtr)
size_t LZ4F_decompress(LZ4F_dctx *dctx, void *dstBuffer, size_t *dstSizePtr, const void *srcBuffer, size_t *srcSizePtr, const LZ4F_decompressOptions_t *decompressOptionsPtr)
unsigned LZ4F_isError(LZ4F_errorCode_t code)
LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_dctx **LZ4F_decompressionContextPtr, unsigned versionNumber)
size_t LZ4F_compressFrame(void *dstBuffer, size_t dstCapacity, const void *srcBuffer, size_t srcSize, const LZ4F_preferences_t *preferencesPtr)
int LZ4_compress_HC_extStateHC(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int compressionLevel)
int LZ4_saveDictHC(LZ4_streamHC_t *LZ4_streamHCPtr, char *safeBuffer, int dictSize)
LZ4_streamHC_t * LZ4_initStreamHC(void *buffer, size_t size)
int LZ4_compress_HC_continue(LZ4_streamHC_t *LZ4_streamHCPtr, const char *src, char *dst, int srcSize, int dstCapacity)
int LZ4_compress_HC(const char *src, char *dst, int srcSize, int dstCapacity, int compressionLevel)
int LZ4_loadDictHC(LZ4_streamHC_t *LZ4_streamHCPtr, const char *dictionary, int dictSize)
assert(limit<=UINT32_MAX/2)