Rizin
unix-like reverse engineering framework and cli tools
bench.h File Reference
#include <stddef.h>

Go to the source code of this file.

Functions

int BMK_benchFiles (const char **fileNamesTable, unsigned nbFiles, int cLevel, int cLevelLast, const char *dictFileName)
 
void BMK_setNbSeconds (unsigned nbLoops)
 
void BMK_setBlockSize (size_t blockSize)
 
void BMK_setAdditionalParam (int additionalParam)
 
void BMK_setNotificationLevel (unsigned level)
 
void BMK_setBenchSeparately (int separate)
 

Function Documentation

◆ BMK_benchFiles()

int BMK_benchFiles ( const char **  fileNamesTable,
unsigned  nbFiles,
int  cLevel,
int  cLevelLast,
const char *  dictFileName 
)

Definition at line 697 of file bench.c.

700 {
701  double const compressibility = (double)g_compressibilityDefault / 100;
702  char* dictBuf = NULL;
703  int dictSize = 0;
704 
705  if (cLevel > LZ4HC_CLEVEL_MAX) cLevel = LZ4HC_CLEVEL_MAX;
706  if (cLevelLast > LZ4HC_CLEVEL_MAX) cLevelLast = LZ4HC_CLEVEL_MAX;
707  if (cLevelLast < cLevel) cLevelLast = cLevel;
708  if (cLevelLast > cLevel) DISPLAYLEVEL(2, "Benchmarking levels from %d to %d\n", cLevel, cLevelLast);
709 
710  if (dictFileName) {
711  FILE* dictFile = NULL;
712  U64 dictFileSize = UTIL_getFileSize(dictFileName);
713  if (!dictFileSize) EXM_THROW(25, "Dictionary error : could not stat dictionary file");
714 
715  dictFile = fopen(dictFileName, "rb");
716  if (!dictFile) EXM_THROW(25, "Dictionary error : could not open dictionary file");
717 
718  if (dictFileSize > LZ4_MAX_DICT_SIZE) {
719  dictSize = LZ4_MAX_DICT_SIZE;
720  if (UTIL_fseek(dictFile, dictFileSize - dictSize, SEEK_SET))
721  EXM_THROW(25, "Dictionary error : could not seek dictionary file");
722  } else {
723  dictSize = (int)dictFileSize;
724  }
725 
726  dictBuf = (char *)malloc(dictSize);
727  if (!dictBuf) EXM_THROW(25, "Allocation error : not enough memory");
728 
729  if (fread(dictBuf, 1, dictSize, dictFile) != (size_t)dictSize)
730  EXM_THROW(25, "Dictionary error : could not read dictionary file");
731 
732  fclose(dictFile);
733  }
734 
735  if (nbFiles == 0)
736  BMK_syntheticTest(cLevel, cLevelLast, compressibility, dictBuf, dictSize);
737  else {
738  if (g_benchSeparately)
739  BMK_benchFilesSeparately(fileNamesTable, nbFiles, cLevel, cLevelLast, dictBuf, dictSize);
740  else
741  BMK_benchFileTable(fileNamesTable, nbFiles, cLevel, cLevelLast, dictBuf, dictSize);
742  }
743 
744  free(dictBuf);
745  return 0;
746 }
#define EXM_THROW(error,...)
Definition: bench.c:270
int g_benchSeparately
Definition: bench.c:286
static U32 g_compressibilityDefault
Definition: bench.c:245
#define DISPLAYLEVEL(l,...)
Definition: bench.c:252
int BMK_benchFilesSeparately(const char **fileNamesTable, unsigned nbFiles, int cLevel, int cLevelLast, const char *dictBuf, int dictSize)
Definition: bench.c:680
#define LZ4_MAX_DICT_SIZE
Definition: bench.c:241
static void BMK_syntheticTest(int cLevel, int cLevelLast, double compressibility, const char *dictBuf, int dictSize)
Definition: bench.c:658
static void BMK_benchFileTable(const char **fileNamesTable, unsigned nbFiles, int cLevel, int cLevelLast, const char *dictBuf, int dictSize)
Definition: bench.c:614
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
void * malloc(size_t size)
Definition: malloc.c:123
#define UTIL_fseek
Definition: util.h:91
UTIL_STATIC U64 UTIL_getFileSize(const char *infilename)
Definition: util.h:407
unsigned long long U64
Definition: lz4.c:290
#define LZ4HC_CLEVEL_MAX
Definition: lz4hc.h:50
string FILE
Definition: benchmark.py:21
static int
Definition: sfsocketcall.h:114
#define SEEK_SET
Definition: zip.c:88

References BMK_benchFilesSeparately(), BMK_benchFileTable(), BMK_syntheticTest(), compressionParameters::cLevel, compressionParameters::dictBuf, compressionParameters::dictSize, DISPLAYLEVEL, EXM_THROW, benchmark::FILE, free(), g_benchSeparately, g_compressibilityDefault, int, LZ4_MAX_DICT_SIZE, LZ4HC_CLEVEL_MAX, malloc(), NULL, SEEK_SET, UTIL_fseek, and UTIL_getFileSize().

Referenced by main().

◆ BMK_setAdditionalParam()

void BMK_setAdditionalParam ( int  additionalParam)

Definition at line 290 of file bench.c.

290 { g_additionalParam=additionalParam; }
int g_additionalParam
Definition: bench.c:285

References g_additionalParam.

◆ BMK_setBenchSeparately()

void BMK_setBenchSeparately ( int  separate)

Definition at line 300 of file bench.c.

300 { g_benchSeparately = (separate!=0); }

References g_benchSeparately.

Referenced by main().

◆ BMK_setBlockSize()

void BMK_setBlockSize ( size_t  blockSize)

Definition at line 298 of file bench.c.

298 { g_blockSize = blockSize; }
static size_t g_blockSize
Definition: bench.c:284

References g_blockSize.

Referenced by main().

◆ BMK_setNbSeconds()

void BMK_setNbSeconds ( unsigned  nbLoops)

Definition at line 292 of file bench.c.

293 {
294  g_nbSeconds = nbSeconds;
295  DISPLAYLEVEL(3, "- test >= %u seconds per compression / decompression -\n", g_nbSeconds);
296 }
static U32 g_nbSeconds
Definition: bench.c:283

References DISPLAYLEVEL, and g_nbSeconds.

Referenced by main().

◆ BMK_setNotificationLevel()

void BMK_setNotificationLevel ( unsigned  level)

Definition at line 288 of file bench.c.

static U32 g_displayLevel
Definition: bench.c:253
static int level
Definition: vmenus.c:2424

References g_displayLevel, and level.

Referenced by main().