Rizin
unix-like reverse engineering framework and cli tools
fullbench.c File Reference
#include "platform.h"
#include "util.h"
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <time.h>
#include "lz4.h"
#include "lz4hc.h"
#include "lz4frame.h"
#include "xxhash.h"

Go to the source code of this file.

Classes

struct  chunkParameters
 

Macros

#define LZ4_DISABLE_DEPRECATE_WARNINGS   /* LZ4_decompress_fast */
 
#define PROGRAM_DESCRIPTION   "LZ4 speed analyzer"
 
#define AUTHOR   "Yann Collet"
 
#define WELCOME_MESSAGE   "*** %s v%s %i-bits, by %s ***\n", PROGRAM_DESCRIPTION, LZ4_VERSION_STRING, (int)(sizeof(void*)*8), AUTHOR
 
#define NBLOOPS   6
 
#define TIMELOOP   (CLOCKS_PER_SEC * 25 / 10)
 
#define KB   *(1 <<10)
 
#define MB   *(1 <<20)
 
#define GB   *(1U<<30)
 
#define KNUTH   2654435761U
 
#define MAX_MEM   (1920 MB)
 
#define DEFAULT_CHUNKSIZE   (4 MB)
 
#define ALL_COMPRESSORS   0
 
#define ALL_DECOMPRESSORS   0
 
#define DISPLAY(...)   fprintf(stderr, __VA_ARGS__)
 
#define PROGRESS(...)   g_noPrompt ? 0 : DISPLAY(__VA_ARGS__)
 
#define NB_COMPRESSION_ALGORITHMS   100
 
#define NB_DECOMPRESSION_ALGORITHMS   100
 

Functions

static void BMK_setBlocksize (int bsize)
 
static void BMK_setNbIterations (int nbLoops)
 
static void BMK_setPause (void)
 
static clock_t BMK_GetClockSpan (clock_t clockStart)
 
static size_t BMK_findMaxMem (U64 requiredMem)
 
void * LZ4_malloc (size_t s)
 
void * LZ4_calloc (size_t n, size_t s)
 
void LZ4_free (void *p)
 
static void local_LZ4_resetDictT (void)
 
static void local_LZ4_createStream (void)
 
static int local_LZ4_saveDict (const char *in, char *out, int inSize)
 
static int local_LZ4_compress_default_large (const char *in, char *out, int inSize)
 
static int local_LZ4_compress_default_small (const char *in, char *out, int inSize)
 
static int local_LZ4_compress_destSize (const char *in, char *out, int inSize)
 
static int local_LZ4_compress_fast0 (const char *in, char *out, int inSize)
 
static int local_LZ4_compress_fast1 (const char *in, char *out, int inSize)
 
static int local_LZ4_compress_fast2 (const char *in, char *out, int inSize)
 
static int local_LZ4_compress_fast17 (const char *in, char *out, int inSize)
 
static int local_LZ4_compress_fast_extState0 (const char *in, char *out, int inSize)
 
static int local_LZ4_compress_fast_continue0 (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_compress_forceDict (const char *in, char *out, int inSize)
 
static void local_LZ4_resetStreamHC (void)
 
static int local_LZ4_saveDictHC (const char *in, char *out, int inSize)
 
static int local_LZ4_compress_HC (const char *in, char *out, int inSize)
 
static int local_LZ4_compress_HC_extStateHC (const char *in, char *out, int inSize)
 
static int local_LZ4_compress_HC_continue (const char *in, char *out, int inSize)
 
static int local_LZ4_decompress_fast (const char *in, char *out, int inSize, int outSize)
 
static int local_LZ4_decompress_fast_usingDict_prefix (const char *in, char *out, int inSize, int outSize)
 
static int local_LZ4_decompress_fast_usingExtDict (const char *in, char *out, int inSize, int outSize)
 
static int local_LZ4_decompress_safe_withPrefix64k (const char *in, char *out, int inSize, int outSize)
 
static int local_LZ4_decompress_safe_usingDict (const char *in, char *out, int inSize, int outSize)
 
int LZ4_decompress_safe_forceExtDict (const char *in, char *out, int inSize, int outSize, const void *dict, size_t dictSize)
 
static int local_LZ4_decompress_safe_forceExtDict (const char *in, char *out, int inSize, int outSize)
 
static int local_LZ4_decompress_safe_partial (const char *in, char *out, int inSize, int outSize)
 
static int local_LZ4F_compressFrame (const char *in, char *out, int inSize)
 
static int local_LZ4F_decompress (const char *in, char *out, int inSize, int outSize)
 
static int local_LZ4F_decompress_followHint (const char *src, char *dst, int srcSize, int dstSize)
 
static int local_LZ4F_decompress_noHint (const char *src, char *dst, int srcSize, int dstSize)
 
int fullSpeedBench (const char **fileNamesTable, int nbFiles)
 
static int usage (const char *exename)
 
static int usage_advanced (void)
 
static int badusage (const char *exename)
 
int main (int argc, const char **argv)
 

Variables

static int g_chunkSize = DEFAULT_CHUNKSIZE
 
static int g_nbIterations = NBLOOPS
 
static int g_pause = 0
 
static int g_compressionTest = 1
 
static int g_compressionAlgo = ALL_COMPRESSORS
 
static int g_decompressionTest = 1
 
static int g_decompressionAlgo = ALL_DECOMPRESSORS
 
static int g_noPrompt = 0
 
static LZ4_stream_t LZ4_stream
 
LZ4_streamHC_t LZ4_streamHC
 
static LZ4F_decompressionContext_t g_dCtx
 

Macro Definition Documentation

◆ ALL_COMPRESSORS

#define ALL_COMPRESSORS   0

Definition at line 71 of file fullbench.c.

◆ ALL_DECOMPRESSORS

#define ALL_DECOMPRESSORS   0

Definition at line 72 of file fullbench.c.

◆ AUTHOR

#define AUTHOR   "Yann Collet"

Definition at line 57 of file fullbench.c.

◆ DEFAULT_CHUNKSIZE

#define DEFAULT_CHUNKSIZE   (4 MB)

Definition at line 69 of file fullbench.c.

◆ DISPLAY

#define DISPLAY (   ...)    fprintf(stderr, __VA_ARGS__)

Definition at line 91 of file fullbench.c.

◆ GB

#define GB   *(1U<<30)

Definition at line 65 of file fullbench.c.

◆ KB

#define KB   *(1 <<10)

Definition at line 63 of file fullbench.c.

◆ KNUTH

#define KNUTH   2654435761U

Definition at line 67 of file fullbench.c.

◆ LZ4_DISABLE_DEPRECATE_WARNINGS

#define LZ4_DISABLE_DEPRECATE_WARNINGS   /* LZ4_decompress_fast */

Definition at line 45 of file fullbench.c.

◆ MAX_MEM

#define MAX_MEM   (1920 MB)

Definition at line 68 of file fullbench.c.

◆ MB

#define MB   *(1 <<20)

Definition at line 64 of file fullbench.c.

◆ NB_COMPRESSION_ALGORITHMS

#define NB_COMPRESSION_ALGORITHMS   100

Definition at line 431 of file fullbench.c.

◆ NB_DECOMPRESSION_ALGORITHMS

#define NB_DECOMPRESSION_ALGORITHMS   100

Definition at line 432 of file fullbench.c.

◆ NBLOOPS

#define NBLOOPS   6

Definition at line 60 of file fullbench.c.

◆ PROGRAM_DESCRIPTION

#define PROGRAM_DESCRIPTION   "LZ4 speed analyzer"

Definition at line 56 of file fullbench.c.

◆ PROGRESS

#define PROGRESS (   ...)    g_noPrompt ? 0 : DISPLAY(__VA_ARGS__)

Definition at line 92 of file fullbench.c.

◆ TIMELOOP

#define TIMELOOP   (CLOCKS_PER_SEC * 25 / 10)

Definition at line 61 of file fullbench.c.

◆ WELCOME_MESSAGE

#define WELCOME_MESSAGE   "*** %s v%s %i-bits, by %s ***\n", PROGRAM_DESCRIPTION, LZ4_VERSION_STRING, (int)(sizeof(void*)*8), AUTHOR

Definition at line 58 of file fullbench.c.

Function Documentation

◆ badusage()

static int badusage ( const char *  exename)
static

Definition at line 760 of file fullbench.c.

761 {
762  DISPLAY("Wrong parameters\n");
763  usage(exename);
764  return 0;
765 }
#define DISPLAY(...)
Definition: fullbench.c:91
static int usage(const char *exename)
Definition: fullbench.c:739

References DISPLAY, and usage().

Referenced by main().

◆ BMK_findMaxMem()

static size_t BMK_findMaxMem ( U64  requiredMem)
static

Definition at line 134 of file fullbench.c.

135 {
136  size_t step = 64 MB;
137  BYTE* testmem = NULL;
138 
139  requiredMem = (((requiredMem >> 26) + 1) << 26);
140  requiredMem += 2*step;
141  if (requiredMem > MAX_MEM) requiredMem = MAX_MEM;
142 
143  while (!testmem) {
144  if (requiredMem > step) requiredMem -= step;
145  else requiredMem >>= 1;
146  testmem = (BYTE*) malloc ((size_t)requiredMem);
147  }
148  free (testmem);
149 
150  /* keep some space available */
151  if (requiredMem > step) requiredMem -= step;
152  else requiredMem >>= 1;
153 
154  return (size_t)requiredMem;
155 }
#define NULL
Definition: cris-opc.c:27
static states step(struct re_guts *, sopno, sopno, states, int, states)
Definition: engine.c:888
#define MB
Definition: fullbench.c:64
#define MAX_MEM
Definition: fullbench.c:68
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
void * malloc(size_t size)
Definition: malloc.c:123
unsigned char BYTE
Definition: lz4.c:286

References free(), malloc(), MAX_MEM, MB, NULL, and step().

Referenced by fullSpeedBench().

◆ BMK_GetClockSpan()

static clock_t BMK_GetClockSpan ( clock_t  clockStart)
static

Definition at line 128 of file fullbench.c.

129 {
130  return clock() - clockStart; /* works even if overflow; max span ~30 mn */
131 }

Referenced by fullSpeedBench().

◆ BMK_setBlocksize()

static void BMK_setBlocksize ( int  bsize)
static

Definition at line 107 of file fullbench.c.

108 {
109  g_chunkSize = bsize;
110  DISPLAY("-Using Block Size of %i KB-\n", g_chunkSize>>10);
111 }
static int g_chunkSize
Definition: fullbench.c:98

References DISPLAY, and g_chunkSize.

Referenced by main().

◆ BMK_setNbIterations()

static void BMK_setNbIterations ( int  nbLoops)
static

Definition at line 113 of file fullbench.c.

114 {
115  g_nbIterations = nbLoops;
116  DISPLAY("- %i iterations -\n", g_nbIterations);
117 }
static int g_nbIterations
Definition: fullbench.c:99

References DISPLAY, and g_nbIterations.

Referenced by main().

◆ BMK_setPause()

static void BMK_setPause ( void  )
static

Definition at line 119 of file fullbench.c.

120 {
121  g_pause = 1;
122 }
static int g_pause
Definition: fullbench.c:100

References g_pause.

Referenced by main().

◆ fullSpeedBench()

int fullSpeedBench ( const char **  fileNamesTable,
int  nbFiles 
)

Definition at line 433 of file fullbench.c.

434 {
435  int fileIdx=0;
436 
437  /* Init */
438  { size_t const errorCode = LZ4F_createDecompressionContext(&g_dCtx, LZ4F_VERSION);
439  if (LZ4F_isError(errorCode)) { DISPLAY("dctx allocation issue \n"); return 10; } }
440 
441  /* Loop for each fileName */
442  while (fileIdx<nbFiles) {
443  char* orig_buff = NULL;
444  struct chunkParameters* chunkP = NULL;
445  char* compressed_buff=NULL;
446  const char* const inFileName = fileNamesTable[fileIdx++];
447  FILE* const inFile = fopen( inFileName, "rb" );
448  U64 const inFileSize = UTIL_getFileSize(inFileName);
449  size_t benchedSize = BMK_findMaxMem(inFileSize*2) / 2; /* because 2 buffers */
450  int nbChunks;
451  int maxCompressedChunkSize;
452  size_t readSize;
453  int compressedBuffSize;
454  U32 crcOriginal;
455 
456  /* Check infile pre-requisites */
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; }
460 
461  /* Memory size adjustments */
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));
466  }
467 
468  /* Allocation */
469  chunkP = (struct chunkParameters*) malloc(((benchedSize / (size_t)g_chunkSize)+1) * sizeof(struct chunkParameters));
470  orig_buff = (char*) malloc(benchedSize);
471  nbChunks = (int) ((benchedSize + (size_t)g_chunkSize - 1) / (size_t)g_chunkSize);
472  maxCompressedChunkSize = LZ4_compressBound(g_chunkSize);
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");
477  fclose(inFile);
478  free(orig_buff);
479  free(compressed_buff);
480  free(chunkP);
481  return(12);
482  }
483 
484  /* Fill in src buffer */
485  DISPLAY("Loading %s... \r", inFileName);
486  readSize = fread(orig_buff, 1, benchedSize, inFile);
487  fclose(inFile);
488 
489  if (readSize != benchedSize) {
490  DISPLAY("\nError: problem reading file '%s' !! \n", inFileName);
491  free(orig_buff);
492  free(compressed_buff);
493  free(chunkP);
494  return 13;
495  }
496 
497  /* Calculating input Checksum */
498  crcOriginal = XXH32(orig_buff, benchedSize,0);
499 
500 
501  /* Bench */
502  { int loopNb, nb_loops, chunkNb, cAlgNb, dAlgNb;
503  size_t cSize=0;
504  double ratio=0.;
505 
506  DISPLAY("\r%79s\r", "");
507  DISPLAY(" %s : \n", inFileName);
508 
509  /* Bench Compression Algorithms */
510  for (cAlgNb=0; (cAlgNb <= NB_COMPRESSION_ALGORITHMS) && (g_compressionTest); cAlgNb++) {
511  const char* compressorName;
512  int (*compressionFunction)(const char*, char*, int);
513  void (*initFunction)(void) = NULL;
514  double bestTime = 100000000.;
515 
516  /* filter compressionAlgo only */
517  if ((g_compressionAlgo != ALL_COMPRESSORS) && (g_compressionAlgo != cAlgNb)) continue;
518 
519  /* Init data chunks */
520  { int i;
521  size_t remaining = benchedSize;
522  char* in = orig_buff;
523  char* out = compressed_buff;
524  assert(nbChunks >= 1);
525  for (i=0; i<nbChunks; i++) {
526  chunkP[i].id = (U32)i;
527  chunkP[i].origBuffer = in; in += g_chunkSize;
528  assert(g_chunkSize > 0);
529  if (remaining > (size_t)g_chunkSize) {
530  chunkP[i].origSize = g_chunkSize;
531  remaining -= (size_t)g_chunkSize;
532  } else {
533  chunkP[i].origSize = (int)remaining;
534  remaining = 0;
535  }
536  chunkP[i].compressedBuffer = out; out += maxCompressedChunkSize;
537  chunkP[i].compressedSize = 0;
538  }
539  }
540 
541  switch(cAlgNb)
542  {
543  case 0 : DISPLAY("Compression functions : \n"); continue;
544  case 1 : compressionFunction = local_LZ4_compress_default_large; compressorName = "LZ4_compress_default"; break;
545  case 2 : compressionFunction = local_LZ4_compress_default_small; compressorName = "LZ4_compress_default(small dst)"; break;
546  case 3 : compressionFunction = local_LZ4_compress_destSize; compressorName = "LZ4_compress_destSize"; break;
547  case 4 : compressionFunction = local_LZ4_compress_fast0; compressorName = "LZ4_compress_fast(0)"; break;
548  case 5 : compressionFunction = local_LZ4_compress_fast1; compressorName = "LZ4_compress_fast(1)"; break;
549  case 6 : compressionFunction = local_LZ4_compress_fast2; compressorName = "LZ4_compress_fast(2)"; break;
550  case 7 : compressionFunction = local_LZ4_compress_fast17; compressorName = "LZ4_compress_fast(17)"; break;
551  case 8 : compressionFunction = local_LZ4_compress_fast_extState0; compressorName = "LZ4_compress_fast_extState(0)"; break;
552  case 9 : compressionFunction = local_LZ4_compress_fast_continue0; initFunction = local_LZ4_createStream; compressorName = "LZ4_compress_fast_continue(0)"; break;
553 
554  case 10: compressionFunction = local_LZ4_compress_HC; compressorName = "LZ4_compress_HC"; break;
555  case 12: compressionFunction = local_LZ4_compress_HC_extStateHC; compressorName = "LZ4_compress_HC_extStateHC"; break;
556  case 14: compressionFunction = local_LZ4_compress_HC_continue; initFunction = local_LZ4_resetStreamHC; compressorName = "LZ4_compress_HC_continue"; break;
557 #ifndef LZ4_DLL_IMPORT
558  case 20: compressionFunction = local_LZ4_compress_forceDict; initFunction = local_LZ4_resetDictT; compressorName = "LZ4_compress_forceDict"; break;
559 #endif
560  case 30: compressionFunction = local_LZ4F_compressFrame; compressorName = "LZ4F_compressFrame";
561  chunkP[0].origSize = (int)benchedSize; nbChunks=1;
562  break;
563  case 40: compressionFunction = local_LZ4_saveDict; compressorName = "LZ4_saveDict";
564  if (chunkP[0].origSize < 8) { DISPLAY(" cannot bench %s with less then 8 bytes \n", compressorName); continue; }
565  LZ4_loadDict(&LZ4_stream, chunkP[0].origBuffer, chunkP[0].origSize);
566  break;
567  case 41: compressionFunction = local_LZ4_saveDictHC; compressorName = "LZ4_saveDictHC";
568  if (chunkP[0].origSize < 8) { DISPLAY(" cannot bench %s with less then 8 bytes \n", compressorName); continue; }
569  LZ4_loadDictHC(&LZ4_streamHC, chunkP[0].origBuffer, chunkP[0].origSize);
570  break;
571  default :
572  continue; /* unknown ID : just skip */
573  }
574 
575  for (loopNb = 1; loopNb <= g_nbIterations; loopNb++) {
576  double averageTime;
577  clock_t clockTime;
578 
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; } /* warming up memory */
581 
582  nb_loops = 0;
583  clockTime = clock();
584  while(clock() == clockTime);
585  clockTime = clock();
586  while(BMK_GetClockSpan(clockTime) < TIMELOOP) {
587  if (initFunction!=NULL) initFunction();
588  for (chunkNb=0; chunkNb<nbChunks; chunkNb++) {
589  chunkP[chunkNb].compressedSize = compressionFunction(chunkP[chunkNb].origBuffer, chunkP[chunkNb].compressedBuffer, chunkP[chunkNb].origSize);
590  if (chunkP[chunkNb].compressedSize==0) {
591  DISPLAY("ERROR ! %s() = 0 !! \n", compressorName);
592  exit(1);
593  } }
594  nb_loops++;
595  }
596  clockTime = BMK_GetClockSpan(clockTime);
597 
598  nb_loops += !nb_loops; /* avoid division by zero */
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);
604  }
605 
606  if (ratio<100.)
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);
608  else
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);
610  }
611 
612  /* Prepare layout for decompression */
613  /* Init data chunks */
614  { int i;
615  size_t remaining = benchedSize;
616  char* in = orig_buff;
617  char* out = compressed_buff;
618 
619  nbChunks = (int) (((int)benchedSize + (g_chunkSize-1))/ g_chunkSize);
620  for (i=0; i<nbChunks; i++) {
621  chunkP[i].id = (U32)i;
622  chunkP[i].origBuffer = in; in += g_chunkSize;
623  if ((int)remaining > g_chunkSize) {
624  chunkP[i].origSize = g_chunkSize;
625  remaining -= (size_t)g_chunkSize;
626  } else {
627  chunkP[i].origSize = (int)remaining;
628  remaining = 0;
629  }
630  chunkP[i].compressedBuffer = out; out += maxCompressedChunkSize;
631  chunkP[i].compressedSize = 0;
632  }
633  }
634  for (chunkNb=0; chunkNb<nbChunks; chunkNb++) {
635  chunkP[chunkNb].compressedSize = LZ4_compress_default(chunkP[chunkNb].origBuffer, chunkP[chunkNb].compressedBuffer, chunkP[chunkNb].origSize, maxCompressedChunkSize);
636  if (chunkP[chunkNb].compressedSize==0) {
637  DISPLAY("ERROR ! %s() = 0 !! \n", "LZ4_compress");
638  exit(1);
639  } }
640 
641  /* Decompression Algorithms */
642  for (dAlgNb=0; (dAlgNb <= NB_DECOMPRESSION_ALGORITHMS) && g_decompressionTest; dAlgNb++) {
643  const char* dName = NULL;
644  int (*decompressionFunction)(const char*, char*, int, int) = NULL;
645  double bestTime = 100000000.;
646  int checkResult = 1;
647 
648  if ((g_decompressionAlgo != ALL_DECOMPRESSORS) && (g_decompressionAlgo != dAlgNb)) continue;
649 
650  switch(dAlgNb)
651  {
652  case 0: DISPLAY("Decompression functions : \n"); continue;
653  case 1: decompressionFunction = local_LZ4_decompress_fast; dName = "LZ4_decompress_fast"; break;
654  case 2: decompressionFunction = local_LZ4_decompress_fast_usingDict_prefix; dName = "LZ4_decompress_fast_usingDict(prefix)"; break;
655  case 3: decompressionFunction = local_LZ4_decompress_fast_usingExtDict; dName = "LZ4_decompress_fast_using(Ext)Dict"; break;
656  case 4: decompressionFunction = LZ4_decompress_safe; dName = "LZ4_decompress_safe"; break;
657  case 5: decompressionFunction = local_LZ4_decompress_safe_withPrefix64k; dName = "LZ4_decompress_safe_withPrefix64k"; break;
658  case 6: decompressionFunction = local_LZ4_decompress_safe_usingDict; dName = "LZ4_decompress_safe_usingDict"; break;
659  case 7: decompressionFunction = local_LZ4_decompress_safe_partial; dName = "LZ4_decompress_safe_partial"; checkResult = 0; break;
660 #ifndef LZ4_DLL_IMPORT
661  case 8: decompressionFunction = local_LZ4_decompress_safe_forceExtDict; dName = "LZ4_decompress_safe_forceExtDict"; break;
662 #endif
663  case 10:
664  case 11:
665  case 12:
666  if (dAlgNb == 10) { decompressionFunction = local_LZ4F_decompress; dName = "LZ4F_decompress"; } /* can be skipped */
667  if (dAlgNb == 11) { decompressionFunction = local_LZ4F_decompress_followHint; dName = "LZ4F_decompress_followHint"; } /* can be skipped */
668  if (dAlgNb == 12) { decompressionFunction = local_LZ4F_decompress_noHint; dName = "LZ4F_decompress_noHint"; } /* can be skipped */
669  /* prepare compressed data using frame format */
670  { size_t const fcsize = LZ4F_compressFrame(compressed_buff, (size_t)compressedBuffSize, orig_buff, benchedSize, NULL);
671  assert(!LZ4F_isError(fcsize));
672  chunkP[0].origSize = (int)benchedSize;
673  chunkP[0].compressedSize = (int)fcsize;
674  nbChunks = 1;
675  break;
676  }
677  default :
678  continue; /* skip if unknown ID */
679  }
680 
681  assert(decompressionFunction != NULL);
682  assert(dName != NULL);
683 
684  { size_t i; for (i=0; i<benchedSize; i++) orig_buff[i]=0; } /* zeroing source area, for CRC checking */
685 
686  for (loopNb = 1; loopNb <= g_nbIterations; loopNb++) {
687  double averageTime;
688  clock_t clockTime;
689  U32 crcDecoded;
690 
691  PROGRESS("%2i-%-34.34s :%10i ->\r", loopNb, dName, (int)benchedSize);
692 
693  nb_loops = 0;
694  clockTime = clock();
695  while(clock() == clockTime);
696  clockTime = clock();
697  while(BMK_GetClockSpan(clockTime) < TIMELOOP) {
698  for (chunkNb=0; chunkNb<nbChunks; chunkNb++) {
699  int const decodedSize = decompressionFunction(chunkP[chunkNb].compressedBuffer, chunkP[chunkNb].origBuffer,
700  chunkP[chunkNb].compressedSize, chunkP[chunkNb].origSize);
701  if (chunkP[chunkNb].origSize != decodedSize) {
702  DISPLAY("ERROR ! %s() == %i != %i !! \n",
703  dName, decodedSize, chunkP[chunkNb].origSize);
704  exit(1);
705  } }
706  nb_loops++;
707  }
708  clockTime = BMK_GetClockSpan(clockTime);
709 
710  nb_loops += !nb_loops; /* Avoid division by zero */
711  averageTime = (double)clockTime / nb_loops / CLOCKS_PER_SEC;
712  if (averageTime < bestTime) bestTime = averageTime;
713 
714  PROGRESS("%2i-%-34.34s :%10i -> %7.1f MB/s\r", loopNb, dName, (int)benchedSize, (double)benchedSize / bestTime / 1000000);
715 
716  /* CRC Checking */
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);
721  exit(1);
722  } }
723 
724  DISPLAY("%2i-%-34.34s :%10i -> %7.1f MB/s\n", dAlgNb, dName, (int)benchedSize, (double)benchedSize / bestTime / 1000000);
725  }
726  }
727  free(orig_buff);
728  free(compressed_buff);
729  free(chunkP);
730  }
731 
733  if (g_pause) { printf("press enter...\n"); (void)getchar(); }
734 
735  return 0;
736 }
lzma_index ** i
Definition: index.h:629
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
static int local_LZ4_compress_fast2(const char *in, char *out, int inSize)
Definition: fullbench.c:213
#define NB_DECOMPRESSION_ALGORITHMS
Definition: fullbench.c:432
static int local_LZ4F_compressFrame(const char *in, char *out, int inSize)
Definition: fullbench.c:343
#define PROGRESS(...)
Definition: fullbench.c:92
static int local_LZ4_decompress_fast_usingDict_prefix(const char *in, char *out, int inSize, int outSize)
Definition: fullbench.c:289
static int g_decompressionAlgo
Definition: fullbench.c:104
static int local_LZ4_decompress_fast_usingExtDict(const char *in, char *out, int inSize, int outSize)
Definition: fullbench.c:296
#define TIMELOOP
Definition: fullbench.c:61
LZ4_streamHC_t LZ4_streamHC
Definition: fullbench.c:253
static int local_LZ4_compress_fast0(const char *in, char *out, int inSize)
Definition: fullbench.c:203
#define ALL_COMPRESSORS
Definition: fullbench.c:71
static int local_LZ4F_decompress(const char *in, char *out, int inSize, int outSize)
Definition: fullbench.c:351
static int local_LZ4_compress_HC(const char *in, char *out, int inSize)
Definition: fullbench.c:265
static int g_decompressionTest
Definition: fullbench.c:103
static int local_LZ4_compress_fast_extState0(const char *in, char *out, int inSize)
Definition: fullbench.c:223
static int local_LZ4_compress_default_large(const char *in, char *out, int inSize)
Definition: fullbench.c:188
#define ALL_DECOMPRESSORS
Definition: fullbench.c:72
static int local_LZ4_compress_destSize(const char *in, char *out, int inSize)
Definition: fullbench.c:198
static clock_t BMK_GetClockSpan(clock_t clockStart)
Definition: fullbench.c:128
static int local_LZ4_compress_HC_extStateHC(const char *in, char *out, int inSize)
Definition: fullbench.c:270
static int local_LZ4_decompress_safe_withPrefix64k(const char *in, char *out, int inSize, int outSize)
Definition: fullbench.c:303
static int local_LZ4_decompress_safe_forceExtDict(const char *in, char *out, int inSize, int outSize)
Definition: fullbench.c:326
static int local_LZ4_compress_fast17(const char *in, char *out, int inSize)
Definition: fullbench.c:218
static int local_LZ4_saveDictHC(const char *in, char *out, int inSize)
Definition: fullbench.c:259
static size_t BMK_findMaxMem(U64 requiredMem)
Definition: fullbench.c:134
static int local_LZ4_compress_fast1(const char *in, char *out, int inSize)
Definition: fullbench.c:208
static int g_compressionAlgo
Definition: fullbench.c:102
static int local_LZ4_decompress_safe_partial(const char *in, char *out, int inSize, int outSize)
Definition: fullbench.c:334
static int local_LZ4F_decompress_followHint(const char *src, char *dst, int srcSize, int dstSize)
Definition: fullbench.c:364
static int g_compressionTest
Definition: fullbench.c:101
static void local_LZ4_resetDictT(void)
Definition: fullbench.c:170
static int local_LZ4F_decompress_noHint(const char *src, char *dst, int srcSize, int dstSize)
Definition: fullbench.c:398
static void local_LZ4_resetStreamHC(void)
Definition: fullbench.c:254
static int local_LZ4_compress_fast_continue0(const char *in, char *out, int inSize)
Definition: fullbench.c:228
static int local_LZ4_compress_forceDict(const char *in, char *out, int inSize)
Definition: fullbench.c:245
static int local_LZ4_decompress_safe_usingDict(const char *in, char *out, int inSize, int outSize)
Definition: fullbench.c:309
static int local_LZ4_compress_HC_continue(const char *in, char *out, int inSize)
Definition: fullbench.c:275
static int local_LZ4_compress_default_small(const char *in, char *out, int inSize)
Definition: fullbench.c:193
static int local_LZ4_saveDict(const char *in, char *out, int inSize)
Definition: fullbench.c:182
static int local_LZ4_decompress_fast(const char *in, char *out, int inSize, int outSize)
Definition: fullbench.c:282
static LZ4F_decompressionContext_t g_dCtx
Definition: fullbench.c:349
static void local_LZ4_createStream(void)
Definition: fullbench.c:176
static LZ4_stream_t LZ4_stream
Definition: fullbench.c:169
#define NB_COMPRESSION_ALGORITHMS
Definition: fullbench.c:431
XXH_PUBLIC_API unsigned int XXH32(const void *input, size_t len, unsigned int seed)
Definition: xxhash.c:392
UTIL_STATIC U64 UTIL_getFileSize(const char *infilename)
Definition: util.h:407
unsigned long long U64
Definition: lz4.c:290
int LZ4_compressBound(int isize)
Definition: lz4.c:674
int LZ4_loadDict(LZ4_stream_t *LZ4_dict, const char *dictionary, int dictSize)
Definition: lz4.c:1475
int LZ4_compress_default(const char *src, char *dst, int srcSize, int maxOutputSize)
Definition: lz4.c:1373
unsigned int U32
Definition: lz4.c:288
LZ4_FORCE_O2 int LZ4_decompress_safe(const char *source, char *dest, int compressedSize, int maxDecompressedSize)
Definition: lz4.c:2171
char int compressedSize
Definition: lz4.h:724
LZ4F_errorCode_t LZ4F_freeDecompressionContext(LZ4F_dctx *dctx)
Definition: lz4frame.c:1082
unsigned LZ4F_isError(LZ4F_errorCode_t code)
Definition: lz4frame.c:249
LZ4F_errorCode_t LZ4F_createDecompressionContext(LZ4F_dctx **LZ4F_decompressionContextPtr, unsigned versionNumber)
Definition: lz4frame.c:1069
size_t LZ4F_compressFrame(void *dstBuffer, size_t dstCapacity, const void *srcBuffer, size_t srcSize, const LZ4F_preferences_t *preferencesPtr)
Definition: lz4frame.c:429
#define LZ4F_VERSION
Definition: lz4frame.h:242
int LZ4_loadDictHC(LZ4_streamHC_t *LZ4_streamHCPtr, const char *dictionary, int dictSize)
Definition: lz4hc.c:1056
assert(limit<=UINT32_MAX/2)
string FILE
Definition: benchmark.py:21
#define U32(val)
static int
Definition: sfsocketcall.h:114
int size_t
Definition: sftypes.h:40
int clock_t
Definition: sftypes.h:43
char * compressedBuffer
Definition: fullbench.c:82
int compressedSize
Definition: fullbench.c:84
char * origBuffer
Definition: fullbench.c:81

References ALL_COMPRESSORS, ALL_DECOMPRESSORS, assert(), BMK_findMaxMem(), BMK_GetClockSpan(), chunkParameters::compressedBuffer, compressedSize, chunkParameters::compressedSize, test-lz4-speed::default, DISPLAY, test-lz4-list::exit, benchmark::FILE, free(), g_chunkSize, g_compressionAlgo, g_compressionTest, g_dCtx, g_decompressionAlgo, g_decompressionTest, g_nbIterations, g_pause, i, chunkParameters::id, in, int, local_LZ4_compress_default_large(), local_LZ4_compress_default_small(), local_LZ4_compress_destSize(), local_LZ4_compress_fast0(), local_LZ4_compress_fast1(), local_LZ4_compress_fast17(), local_LZ4_compress_fast2(), local_LZ4_compress_fast_continue0(), local_LZ4_compress_fast_extState0(), local_LZ4_compress_forceDict(), local_LZ4_compress_HC(), local_LZ4_compress_HC_continue(), local_LZ4_compress_HC_extStateHC(), local_LZ4_createStream(), local_LZ4_decompress_fast(), local_LZ4_decompress_fast_usingDict_prefix(), local_LZ4_decompress_fast_usingExtDict(), local_LZ4_decompress_safe_forceExtDict(), local_LZ4_decompress_safe_partial(), local_LZ4_decompress_safe_usingDict(), local_LZ4_decompress_safe_withPrefix64k(), local_LZ4_resetDictT(), local_LZ4_resetStreamHC(), local_LZ4_saveDict(), local_LZ4_saveDictHC(), local_LZ4F_compressFrame(), local_LZ4F_decompress(), local_LZ4F_decompress_followHint(), local_LZ4F_decompress_noHint(), LZ4_compress_default(), LZ4_compressBound(), LZ4_decompress_safe(), LZ4_loadDict(), LZ4_loadDictHC(), LZ4_stream, LZ4_streamHC, LZ4F_compressFrame(), LZ4F_createDecompressionContext(), LZ4F_freeDecompressionContext(), LZ4F_isError(), LZ4F_VERSION, malloc(), NB_COMPRESSION_ALGORITHMS, NB_DECOMPRESSION_ALGORITHMS, NULL, chunkParameters::origBuffer, chunkParameters::origSize, out, printf(), PROGRESS, TIMELOOP, U32, UTIL_getFileSize(), and XXH32().

Referenced by main().

◆ local_LZ4_compress_default_large()

static int local_LZ4_compress_default_large ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 188 of file fullbench.c.

189 {
190  return LZ4_compress_default(in, out, inSize, LZ4_compressBound(inSize));
191 }

References in, LZ4_compress_default(), LZ4_compressBound(), and out.

Referenced by fullSpeedBench().

◆ local_LZ4_compress_default_small()

static int local_LZ4_compress_default_small ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 193 of file fullbench.c.

194 {
195  return LZ4_compress_default(in, out, inSize, LZ4_compressBound(inSize)-1);
196 }

References in, LZ4_compress_default(), LZ4_compressBound(), and out.

Referenced by fullSpeedBench().

◆ local_LZ4_compress_destSize()

static int local_LZ4_compress_destSize ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 198 of file fullbench.c.

199 {
200  return LZ4_compress_destSize(in, out, &inSize, LZ4_compressBound(inSize)-1);
201 }
int LZ4_compress_destSize(const char *src, char *dst, int *srcSizePtr, int targetDstSize)
Definition: lz4.c:1399

References in, LZ4_compress_destSize(), LZ4_compressBound(), and out.

Referenced by fullSpeedBench().

◆ local_LZ4_compress_fast0()

static int local_LZ4_compress_fast0 ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 203 of file fullbench.c.

204 {
205  return LZ4_compress_fast(in, out, inSize, LZ4_compressBound(inSize), 0);
206 }
int LZ4_compress_fast(const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
Definition: lz4.c:1354

References in, LZ4_compress_fast(), LZ4_compressBound(), and out.

Referenced by fullSpeedBench().

◆ local_LZ4_compress_fast1()

static int local_LZ4_compress_fast1 ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 208 of file fullbench.c.

209 {
210  return LZ4_compress_fast(in, out, inSize, LZ4_compressBound(inSize), 1);
211 }

References in, LZ4_compress_fast(), LZ4_compressBound(), and out.

Referenced by fullSpeedBench().

◆ local_LZ4_compress_fast17()

static int local_LZ4_compress_fast17 ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 218 of file fullbench.c.

219 {
220  return LZ4_compress_fast(in, out, inSize, LZ4_compressBound(inSize), 17);
221 }

References in, LZ4_compress_fast(), LZ4_compressBound(), and out.

Referenced by fullSpeedBench().

◆ local_LZ4_compress_fast2()

static int local_LZ4_compress_fast2 ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 213 of file fullbench.c.

214 {
215  return LZ4_compress_fast(in, out, inSize, LZ4_compressBound(inSize), 2);
216 }

References in, LZ4_compress_fast(), LZ4_compressBound(), and out.

Referenced by fullSpeedBench().

◆ local_LZ4_compress_fast_continue0()

static int local_LZ4_compress_fast_continue0 ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 228 of file fullbench.c.

229 {
230  return LZ4_compress_fast_continue(&LZ4_stream, in, out, inSize, LZ4_compressBound(inSize), 0);
231 }
int LZ4_compress_fast_continue(LZ4_stream_t *LZ4_stream, const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
Definition: lz4.c:1565

References in, LZ4_compress_fast_continue(), LZ4_compressBound(), LZ4_stream, and out.

Referenced by fullSpeedBench().

◆ local_LZ4_compress_fast_extState0()

static int local_LZ4_compress_fast_extState0 ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 223 of file fullbench.c.

224 {
225  return LZ4_compress_fast_extState(&LZ4_stream, in, out, inSize, LZ4_compressBound(inSize), 0);
226 }
int LZ4_compress_fast_extState(void *state, const char *source, char *dest, int inputSize, int maxOutputSize, int acceleration)
Definition: lz4.c:1284

References in, LZ4_compress_fast_extState(), LZ4_compressBound(), LZ4_stream, and out.

Referenced by fullSpeedBench().

◆ local_LZ4_compress_forceDict()

static int local_LZ4_compress_forceDict ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 245 of file fullbench.c.

246 {
247  return LZ4_compress_forceExtDict(&LZ4_stream, in, out, inSize);
248 }
int LZ4_compress_forceExtDict(LZ4_stream_t *LZ4_stream, const char *source, char *dest, int inputSize)
Definition: lz4.c:1641

References in, LZ4_compress_forceExtDict(), LZ4_stream, and out.

Referenced by fullSpeedBench().

◆ local_LZ4_compress_HC()

static int local_LZ4_compress_HC ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 265 of file fullbench.c.

266 {
267  return LZ4_compress_HC(in, out, inSize, LZ4_compressBound(inSize), 9);
268 }
int LZ4_compress_HC(const char *src, char *dst, int srcSize, int dstCapacity, int compressionLevel)
Definition: lz4hc.c:954

References in, LZ4_compress_HC(), LZ4_compressBound(), and out.

Referenced by fullSpeedBench().

◆ local_LZ4_compress_HC_continue()

static int local_LZ4_compress_HC_continue ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 275 of file fullbench.c.

276 {
277  return LZ4_compress_HC_continue(&LZ4_streamHC, in, out, inSize, LZ4_compressBound(inSize));
278 }
int LZ4_compress_HC_continue(LZ4_streamHC_t *LZ4_streamHCPtr, const char *src, char *dst, int srcSize, int dstCapacity)
Definition: lz4hc.c:1138

References in, LZ4_compress_HC_continue(), LZ4_compressBound(), LZ4_streamHC, and out.

Referenced by fullSpeedBench().

◆ local_LZ4_compress_HC_extStateHC()

static int local_LZ4_compress_HC_extStateHC ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 270 of file fullbench.c.

271 {
272  return LZ4_compress_HC_extStateHC(&LZ4_streamHC, in, out, inSize, LZ4_compressBound(inSize), 9);
273 }
int LZ4_compress_HC_extStateHC(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int compressionLevel)
Definition: lz4hc.c:947

References in, LZ4_compress_HC_extStateHC(), LZ4_compressBound(), LZ4_streamHC, and out.

Referenced by fullSpeedBench().

◆ local_LZ4_createStream()

static void local_LZ4_createStream ( void  )
static

Definition at line 176 of file fullbench.c.

177 {
178  void* const r = LZ4_initStream(&LZ4_stream, sizeof(LZ4_stream));
179  assert(r != NULL); (void)r;
180 }
#define r
Definition: crypto_rc6.c:12
LZ4_stream_t * LZ4_initStream(void *buffer, size_t size)
Definition: lz4.c:1443

References assert(), LZ4_initStream(), LZ4_stream, NULL, and r.

Referenced by fullSpeedBench().

◆ local_LZ4_decompress_fast()

static int local_LZ4_decompress_fast ( const char *  in,
char *  out,
int  inSize,
int  outSize 
)
static

Definition at line 282 of file fullbench.c.

283 {
284  (void)inSize;
285  LZ4_decompress_fast(in, out, outSize);
286  return outSize;
287 }
LZ4_FORCE_O2 int LZ4_decompress_fast(const char *source, char *dest, int originalSize)
Definition: lz4.c:2188

References in, LZ4_decompress_fast(), and out.

Referenced by fullSpeedBench().

◆ local_LZ4_decompress_fast_usingDict_prefix()

static int local_LZ4_decompress_fast_usingDict_prefix ( const char *  in,
char *  out,
int  inSize,
int  outSize 
)
static

Definition at line 289 of file fullbench.c.

290 {
291  (void)inSize;
292  LZ4_decompress_fast_usingDict(in, out, outSize, out - 65536, 65536);
293  return outSize;
294 }
int LZ4_decompress_fast_usingDict(const char *source, char *dest, int originalSize, const char *dictStart, int dictSize)
Definition: lz4.c:2419

References in, LZ4_decompress_fast_usingDict(), and out.

Referenced by fullSpeedBench().

◆ local_LZ4_decompress_fast_usingExtDict()

static int local_LZ4_decompress_fast_usingExtDict ( const char *  in,
char *  out,
int  inSize,
int  outSize 
)
static

Definition at line 296 of file fullbench.c.

297 {
298  (void)inSize;
299  LZ4_decompress_fast_usingDict(in, out, outSize, out - 65536, 65535);
300  return outSize;
301 }

References in, LZ4_decompress_fast_usingDict(), and out.

Referenced by fullSpeedBench().

◆ local_LZ4_decompress_safe_forceExtDict()

static int local_LZ4_decompress_safe_forceExtDict ( const char *  in,
char *  out,
int  inSize,
int  outSize 
)
static

Definition at line 326 of file fullbench.c.

327 {
328  (void)inSize;
329  LZ4_decompress_safe_forceExtDict(in, out, inSize, outSize, out - 65536, 65536);
330  return outSize;
331 }
int LZ4_decompress_safe_forceExtDict(const char *in, char *out, int inSize, int outSize, const void *dict, size_t dictSize)
Definition: lz4.c:2223

References in, LZ4_decompress_safe_forceExtDict(), and out.

Referenced by fullSpeedBench().

◆ local_LZ4_decompress_safe_partial()

static int local_LZ4_decompress_safe_partial ( const char *  in,
char *  out,
int  inSize,
int  outSize 
)
static

Definition at line 334 of file fullbench.c.

335 {
336  int result = LZ4_decompress_safe_partial(in, out, inSize, outSize - 5, outSize);
337  if (result < 0) return result;
338  return outSize;
339 }
LZ4_FORCE_O2 int LZ4_decompress_safe_partial(const char *src, char *dst, int compressedSize, int targetOutputSize, int dstCapacity)
Definition: lz4.c:2179

References in, LZ4_decompress_safe_partial(), and out.

Referenced by fullSpeedBench().

◆ local_LZ4_decompress_safe_usingDict()

static int local_LZ4_decompress_safe_usingDict ( const char *  in,
char *  out,
int  inSize,
int  outSize 
)
static

Definition at line 309 of file fullbench.c.

310 {
311  LZ4_decompress_safe_usingDict(in, out, inSize, outSize, out - 65536, 65536);
312  return outSize;
313 }
int LZ4_decompress_safe_usingDict(const char *source, char *dest, int compressedSize, int maxOutputSize, const char *dictStart, int dictSize)
Definition: lz4.c:2404

References in, LZ4_decompress_safe_usingDict(), and out.

Referenced by fullSpeedBench().

◆ local_LZ4_decompress_safe_withPrefix64k()

static int local_LZ4_decompress_safe_withPrefix64k ( const char *  in,
char *  out,
int  inSize,
int  outSize 
)
static

Definition at line 303 of file fullbench.c.

304 {
305  LZ4_decompress_safe_withPrefix64k(in, out, inSize, outSize);
306  return outSize;
307 }
LZ4_FORCE_O2 int LZ4_decompress_safe_withPrefix64k(const char *source, char *dest, int compressedSize, int maxOutputSize)
Definition: lz4.c:2198

References in, LZ4_decompress_safe_withPrefix64k(), and out.

Referenced by fullSpeedBench().

◆ local_LZ4_resetDictT()

static void local_LZ4_resetDictT ( void  )
static

Definition at line 170 of file fullbench.c.

171 {
172  void* const r = LZ4_initStream(&LZ4_stream, sizeof(LZ4_stream));
173  assert(r != NULL); (void)r;
174 }

References assert(), LZ4_initStream(), LZ4_stream, NULL, and r.

Referenced by fullSpeedBench().

◆ local_LZ4_resetStreamHC()

static void local_LZ4_resetStreamHC ( void  )
static

Definition at line 254 of file fullbench.c.

255 {
257 }
LZ4_streamHC_t * LZ4_initStreamHC(void *buffer, size_t size)
Definition: lz4hc.c:1003

References LZ4_initStreamHC(), and LZ4_streamHC.

Referenced by fullSpeedBench().

◆ local_LZ4_saveDict()

static int local_LZ4_saveDict ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 182 of file fullbench.c.

183 {
184  (void)in;
185  return LZ4_saveDict(&LZ4_stream, out, inSize);
186 }
int LZ4_saveDict(LZ4_stream_t *LZ4_dict, char *safeBuffer, int dictSize)
Definition: lz4.c:1668

References in, LZ4_saveDict(), LZ4_stream, and out.

Referenced by fullSpeedBench().

◆ local_LZ4_saveDictHC()

static int local_LZ4_saveDictHC ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 259 of file fullbench.c.

260 {
261  (void)in;
262  return LZ4_saveDictHC(&LZ4_streamHC, out, inSize);
263 }
int LZ4_saveDictHC(LZ4_streamHC_t *LZ4_streamHCPtr, char *safeBuffer, int dictSize)
Definition: lz4hc.c:1158

References in, LZ4_saveDictHC(), LZ4_streamHC, and out.

Referenced by fullSpeedBench().

◆ local_LZ4F_compressFrame()

static int local_LZ4F_compressFrame ( const char *  in,
char *  out,
int  inSize 
)
static

Definition at line 343 of file fullbench.c.

344 {
345  assert(inSize >= 0);
346  return (int)LZ4F_compressFrame(out, LZ4F_compressFrameBound((size_t)inSize, NULL), in, (size_t)inSize, NULL);
347 }
size_t LZ4F_compressFrameBound(size_t srcSize, const LZ4F_preferences_t *preferencesPtr)
Definition: lz4frame.c:351

References assert(), in, LZ4F_compressFrame(), LZ4F_compressFrameBound(), NULL, and out.

Referenced by fullSpeedBench().

◆ local_LZ4F_decompress()

static int local_LZ4F_decompress ( const char *  in,
char *  out,
int  inSize,
int  outSize 
)
static

Definition at line 351 of file fullbench.c.

352 {
353  size_t srcSize = (size_t)inSize;
354  size_t dstSize = (size_t)outSize;
355  size_t result;
356  assert(inSize >= 0);
357  assert(outSize >= 0);
358  result = LZ4F_decompress(g_dCtx, out, &dstSize, in, &srcSize, NULL);
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); }
361  return (int)dstSize;
362 }
char int srcSize
Definition: lz4.h:697
size_t LZ4F_decompress(LZ4F_dctx *dctx, void *dstBuffer, size_t *dstSizePtr, const void *srcBuffer, size_t *srcSizePtr, const LZ4F_decompressOptions_t *decompressOptionsPtr)
Definition: lz4frame.c:1384

References assert(), DISPLAY, test-lz4-list::exit, g_dCtx, in, LZ4F_decompress(), NULL, out, and srcSize.

Referenced by fullSpeedBench().

◆ local_LZ4F_decompress_followHint()

static int local_LZ4F_decompress_followHint ( const char *  src,
char *  dst,
int  srcSize,
int  dstSize 
)
static

Definition at line 364 of file fullbench.c.

365 {
366  size_t totalInSize = (size_t)srcSize;
367  size_t maxOutSize = (size_t)dstSize;
368 
369  size_t inPos = 0;
370  size_t inSize = 0;
371  size_t outPos = 0;
372  size_t outRemaining = maxOutSize - outPos;
373 
374  for (;;) {
375  size_t const sizeHint = LZ4F_decompress(g_dCtx, dst+outPos, &outRemaining, src+inPos, &inSize, NULL);
376  assert(!LZ4F_isError(sizeHint));
377 
378  inPos += inSize;
379  inSize = sizeHint;
380 
381  outPos += outRemaining;
382  outRemaining = maxOutSize - outPos;
383 
384  if (!sizeHint) break;
385  }
386 
387  /* frame completed */
388  if (inPos != totalInSize) {
389  DISPLAY("Error decompressing frame : must read (%u) full frame (%u) \n",
390  (unsigned)inPos, (unsigned)totalInSize);
391  exit(10);
392  }
393  return (int)outPos;
394 
395 }
lzma_index * src
Definition: index.h:567
char * dst
Definition: lz4.h:724

References assert(), DISPLAY, dst, test-lz4-list::exit, g_dCtx, LZ4F_decompress(), LZ4F_isError(), NULL, src, and srcSize.

Referenced by fullSpeedBench().

◆ local_LZ4F_decompress_noHint()

static int local_LZ4F_decompress_noHint ( const char *  src,
char *  dst,
int  srcSize,
int  dstSize 
)
static

Definition at line 398 of file fullbench.c.

399 {
400  size_t totalInSize = (size_t)srcSize;
401  size_t maxOutSize = (size_t)dstSize;
402 
403  size_t inPos = 0;
404  size_t inSize = 64 KB;
405  size_t outPos = 0;
406  size_t outRemaining = maxOutSize - outPos;
407 
408  for (;;) {
409  size_t const sizeHint = LZ4F_decompress(g_dCtx, dst+outPos, &outRemaining, src+inPos, &inSize, NULL);
410  assert(!LZ4F_isError(sizeHint));
411 
412  inPos += inSize;
413  inSize = (inPos + 64 KB <= totalInSize) ? 64 KB : totalInSize - inPos;
414 
415  outPos += outRemaining;
416  outRemaining = maxOutSize - outPos;
417 
418  if (!sizeHint) break;
419  }
420 
421  /* frame completed */
422  if (inPos != totalInSize) {
423  DISPLAY("Error decompressing frame : must read (%u) full frame (%u) \n",
424  (unsigned)inPos, (unsigned)totalInSize);
425  exit(10);
426  }
427  return (int)outPos;
428 
429 }
#define KB
Definition: fullbench.c:63

References assert(), DISPLAY, dst, test-lz4-list::exit, g_dCtx, KB, LZ4F_decompress(), LZ4F_isError(), NULL, src, and srcSize.

Referenced by fullSpeedBench().

◆ LZ4_calloc()

void* LZ4_calloc ( size_t  n,
size_t  s 
)

Definition at line 162 of file fullbench.c.

162 { return calloc(n,s); }
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
int n
Definition: mipsasm.c:19
static RzSocket * s
Definition: rtr.c:28

References calloc(), n, and s.

◆ LZ4_compress_forceExtDict()

int LZ4_compress_forceExtDict ( LZ4_stream_t LZ4_stream,
const char *  source,
char *  dest,
int  inputSize 
)

Definition at line 1641 of file lz4.c.

1642 {
1643  LZ4_stream_t_internal* streamPtr = &LZ4_dict->internal_donotuse;
1644  int result;
1645 
1646  LZ4_renormDictT(streamPtr, srcSize);
1647 
1648  if ((streamPtr->dictSize < 64 KB) && (streamPtr->dictSize < streamPtr->currentOffset)) {
1650  } else {
1652  }
1653 
1654  streamPtr->dictionary = (const BYTE*)source;
1655  streamPtr->dictSize = (U32)srcSize;
1656 
1657  return result;
1658 }
#define KB
Definition: lz4.c:223
LZ4_FORCE_INLINE int LZ4_compress_generic(LZ4_stream_t_internal *const cctx, const char *const src, char *const dst, const int srcSize, int *inputConsumed, const int dstCapacity, const limitedOutput_directive outputDirective, const tableType_t tableType, const dict_directive dictDirective, const dictIssue_directive dictIssue, const int acceleration)
Definition: lz4.c:1246
@ noDictIssue
Definition: lz4.c:666
@ dictSmall
Definition: lz4.c:666
@ usingExtDict
Definition: lz4.c:665
@ notLimited
Definition: lz4.c:301
@ byU32
Definition: lz4.c:640
static void LZ4_renormDictT(LZ4_stream_t_internal *LZ4_dict, int nextSize)
Definition: lz4.c:1545
const char * source
Definition: lz4.h:699
char * dest
Definition: lz4.h:697
LZ4_u32 currentOffset
Definition: lz4.h:598
const LZ4_byte * dictionary
Definition: lz4.h:600
LZ4_u32 dictSize
Definition: lz4.h:602

References byU32, LZ4_stream_t_internal::currentOffset, dest, LZ4_stream_t_internal::dictionary, LZ4_stream_t_internal::dictSize, dictSmall, LZ4_stream_u::internal_donotuse, KB, LZ4_compress_generic(), LZ4_renormDictT(), noDictIssue, notLimited, NULL, source, srcSize, and usingExtDict.

Referenced by local_LZ4_compress_forceDict().

◆ LZ4_decompress_safe_forceExtDict()

int LZ4_decompress_safe_forceExtDict ( const char *  in,
char *  out,
int  inSize,
int  outSize,
const void *  dict,
size_t  dictSize 
)

Definition at line 2223 of file lz4.c.

2226 {
2229  (BYTE*)dest, (const BYTE*)dictStart, dictSize);
2230 }
@ endOnInputSize
Definition: lz4.c:1692
@ decode_full_block
Definition: lz4.c:1693
LZ4_FORCE_INLINE int LZ4_decompress_generic(const char *const src, char *const dst, int srcSize, int outputSize, endCondition_directive endOnInput, earlyEnd_directive partialDecoding, dict_directive dict, const BYTE *const lowPrefix, const BYTE *const dictStart, const size_t dictSize)
Definition: lz4.c:1738
char int int maxOutputSize
Definition: lz4.h:698

References compressedSize, decode_full_block, dest, endOnInputSize, LZ4_decompress_generic(), maxOutputSize, source, and usingExtDict.

Referenced by local_LZ4_decompress_safe_forceExtDict(), LZ4_decompress_safe_continue(), and LZ4_decompress_safe_usingDict().

◆ LZ4_free()

void LZ4_free ( void *  p)

Definition at line 163 of file fullbench.c.

163 { free(p); }
void * p
Definition: libc.cpp:67

References free(), and p.

◆ LZ4_malloc()

void* LZ4_malloc ( size_t  s)

Definition at line 161 of file fullbench.c.

161 { return malloc(s); }

References malloc(), and s.

◆ main()

int main ( int  argc,
const char **  argv 
)

Definition at line 767 of file fullbench.c.

768 {
769  int i,
770  filenamesStart=2;
771  const char* exename = argv[0];
772  const char* input_filename=0;
773 
774  // Welcome message
776 
777  if (argc<2) { badusage(exename); return 1; }
778 
779  for(i=1; i<argc; i++) {
780  const char* argument = argv[i];
781 
782  if(!argument) continue; // Protection if argument empty
783  if (!strcmp(argument, "--no-prompt")) {
784  g_noPrompt = 1;
785  continue;
786  }
787 
788  // Decode command (note : aggregated commands are allowed)
789  if (argument[0]=='-') {
790  while (argument[1]!=0) {
791  argument ++;
792 
793  switch(argument[0])
794  {
795  // Select compression algorithm only
796  case 'c':
798  while ((argument[1]>= '0') && (argument[1]<= '9')) {
799  g_compressionAlgo *= 10;
800  g_compressionAlgo += argument[1] - '0';
801  argument++;
802  }
803  break;
804 
805  // Select decompression algorithm only
806  case 'd':
807  g_compressionTest = 0;
808  while ((argument[1]>= '0') && (argument[1]<= '9')) {
809  g_decompressionAlgo *= 10;
810  g_decompressionAlgo += argument[1] - '0';
811  argument++;
812  }
813  break;
814 
815  // Display help on usage
816  case 'h' :
817  case 'H': usage(exename); usage_advanced(); return 0;
818 
819  // Modify Block Properties
820  case 'B':
821  while (argument[1]!=0)
822  switch(argument[1])
823  {
824  case '4':
825  case '5':
826  case '6':
827  case '7':
828  { int B = argument[1] - '0';
829  int S = 1 << (8 + 2*B);
831  argument++;
832  break;
833  }
834  case 'D': argument++; break;
835  default : goto _exit_blockProperties;
836  }
837 _exit_blockProperties:
838  break;
839 
840  // Modify Nb Iterations
841  case 'i':
842  if ((argument[1] >='0') && (argument[1] <='9')) {
843  int iters = argument[1] - '0';
844  BMK_setNbIterations(iters);
845  argument++;
846  }
847  break;
848 
849  // Pause at the end (hidden option)
850  case 'p': BMK_setPause(); break;
851 
852  // Unknown command
853  default : badusage(exename); return 1;
854  }
855  }
856  continue;
857  }
858 
859  // first provided filename is input
860  if (!input_filename) { input_filename=argument; filenamesStart=i; continue; }
861 
862  }
863 
864  // No input filename ==> Error
865  if(!input_filename) { badusage(exename); return 1; }
866 
867  return fullSpeedBench(argv+filenamesStart, argc-filenamesStart);
868 
869 }
#define B(x)
Definition: arc.h:166
static void BMK_setPause(void)
Definition: fullbench.c:119
static void BMK_setNbIterations(int nbLoops)
Definition: fullbench.c:113
#define WELCOME_MESSAGE
Definition: fullbench.c:58
static void BMK_setBlocksize(int bsize)
Definition: fullbench.c:107
int fullSpeedBench(const char **fileNamesTable, int nbFiles)
Definition: fullbench.c:433
static int badusage(const char *exename)
Definition: fullbench.c:760
static int g_noPrompt
Definition: fullbench.c:105
static int usage_advanced(void)
Definition: fullbench.c:750
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
#define S
Definition: zip_err_str.c:9

References argv, B, badusage(), BMK_setBlocksize(), BMK_setNbIterations(), BMK_setPause(), test-lz4-speed::default, DISPLAY, fullSpeedBench(), g_compressionAlgo, g_compressionTest, g_decompressionAlgo, g_decompressionTest, g_noPrompt, i, S, usage(), usage_advanced(), and WELCOME_MESSAGE.

◆ usage()

static int usage ( const char *  exename)
static

Definition at line 739 of file fullbench.c.

740 {
741  DISPLAY( "Usage :\n");
742  DISPLAY( " %s [arg] file1 file2 ... fileX\n", exename);
743  DISPLAY( "Arguments :\n");
744  DISPLAY( " -c : compression tests only\n");
745  DISPLAY( " -d : decompression tests only\n");
746  DISPLAY( " -H/-h : Help (this text + advanced options)\n");
747  return 0;
748 }

References DISPLAY.

Referenced by badusage(), and main().

◆ usage_advanced()

static int usage_advanced ( void  )
static

Definition at line 750 of file fullbench.c.

751 {
752  DISPLAY( "\nAdvanced options :\n");
753  DISPLAY( " -c# : test only compression function # [1-%i]\n", NB_COMPRESSION_ALGORITHMS);
754  DISPLAY( " -d# : test only decompression function # [1-%i]\n", NB_DECOMPRESSION_ALGORITHMS);
755  DISPLAY( " -i# : iteration loops [1-9](default : %i)\n", NBLOOPS);
756  DISPLAY( " -B# : Block size [4-7](default : 7)\n");
757  return 0;
758 }
#define NBLOOPS
Definition: fullbench.c:60

References DISPLAY, NB_COMPRESSION_ALGORITHMS, NB_DECOMPRESSION_ALGORITHMS, and NBLOOPS.

Referenced by main().

Variable Documentation

◆ g_chunkSize

int g_chunkSize = DEFAULT_CHUNKSIZE
static

Definition at line 98 of file fullbench.c.

Referenced by BMK_setBlocksize(), and fullSpeedBench().

◆ g_compressionAlgo

int g_compressionAlgo = ALL_COMPRESSORS
static

Definition at line 102 of file fullbench.c.

Referenced by fullSpeedBench(), and main().

◆ g_compressionTest

int g_compressionTest = 1
static

Definition at line 101 of file fullbench.c.

Referenced by fullSpeedBench(), and main().

◆ g_dCtx

◆ g_decompressionAlgo

int g_decompressionAlgo = ALL_DECOMPRESSORS
static

Definition at line 104 of file fullbench.c.

Referenced by fullSpeedBench(), and main().

◆ g_decompressionTest

int g_decompressionTest = 1
static

Definition at line 103 of file fullbench.c.

Referenced by fullSpeedBench(), and main().

◆ g_nbIterations

int g_nbIterations = NBLOOPS
static

Definition at line 99 of file fullbench.c.

Referenced by BMK_setNbIterations(), and fullSpeedBench().

◆ g_noPrompt

int g_noPrompt = 0
static

Definition at line 105 of file fullbench.c.

Referenced by main().

◆ g_pause

int g_pause = 0
static

Definition at line 100 of file fullbench.c.

Referenced by BMK_setPause(), and fullSpeedBench().

◆ LZ4_stream

◆ LZ4_streamHC