2013-12-30 17:16:52 +00:00
|
|
|
/*
|
2015-03-10 15:57:42 +00:00
|
|
|
bench.c - Demo program to benchmark open-source compression algorithms
|
2020-11-25 22:45:14 +00:00
|
|
|
Copyright (C) Yann Collet 2012-2020
|
2015-03-10 15:57:42 +00:00
|
|
|
|
2013-12-30 17:16:52 +00:00
|
|
|
GPL v2 License
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
You can contact the author at :
|
2016-06-29 15:48:28 +00:00
|
|
|
- LZ4 homepage : http://www.lz4.org
|
2016-11-03 14:12:57 +00:00
|
|
|
- LZ4 source repository : https://github.com/lz4/lz4
|
2013-12-30 17:16:52 +00:00
|
|
|
*/
|
|
|
|
|
2016-09-02 19:50:57 +00:00
|
|
|
|
2016-12-21 16:13:38 +00:00
|
|
|
/*-************************************
|
|
|
|
* Compiler options
|
|
|
|
**************************************/
|
|
|
|
#ifdef _MSC_VER /* Visual Studio */
|
|
|
|
# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
/* *************************************
|
2014-12-16 21:03:16 +00:00
|
|
|
* Includes
|
|
|
|
***************************************/
|
2016-12-20 17:05:43 +00:00
|
|
|
#include "platform.h" /* Compiler options */
|
|
|
|
#include "util.h" /* UTIL_GetFileSize, UTIL_sleep */
|
2016-11-04 13:26:12 +00:00
|
|
|
#include <stdlib.h> /* malloc, free */
|
|
|
|
#include <string.h> /* memset */
|
2016-12-20 17:05:43 +00:00
|
|
|
#include <stdio.h> /* fprintf, fopen, ftello */
|
2016-11-04 13:26:12 +00:00
|
|
|
#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */
|
2018-02-20 19:37:19 +00:00
|
|
|
#include <assert.h> /* assert */
|
2016-11-04 13:26:12 +00:00
|
|
|
|
|
|
|
#include "datagen.h" /* RDG_genBuffer */
|
|
|
|
#include "xxhash.h"
|
2019-11-04 19:51:41 +00:00
|
|
|
#include "bench.h"
|
2016-09-02 21:02:30 +00:00
|
|
|
|
2019-11-04 19:51:41 +00:00
|
|
|
#define LZ4_STATIC_LINKING_ONLY
|
2013-12-30 17:16:52 +00:00
|
|
|
#include "lz4.h"
|
2019-11-04 19:51:41 +00:00
|
|
|
#define LZ4_HC_STATIC_LINKING_ONLY
|
2013-12-30 17:16:52 +00:00
|
|
|
#include "lz4hc.h"
|
2019-11-04 19:51:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* *************************************
|
|
|
|
* Compression parameters and functions
|
|
|
|
***************************************/
|
|
|
|
|
|
|
|
struct compressionParameters
|
|
|
|
{
|
|
|
|
int cLevel;
|
|
|
|
const char* dictBuf;
|
|
|
|
int dictSize;
|
|
|
|
|
|
|
|
LZ4_stream_t* LZ4_stream;
|
|
|
|
LZ4_stream_t* LZ4_dictStream;
|
|
|
|
LZ4_streamHC_t* LZ4_streamHC;
|
|
|
|
LZ4_streamHC_t* LZ4_dictStreamHC;
|
|
|
|
|
|
|
|
void (*initFunction)(
|
|
|
|
struct compressionParameters* pThis);
|
|
|
|
void (*resetFunction)(
|
|
|
|
const struct compressionParameters* pThis);
|
|
|
|
int (*blockFunction)(
|
|
|
|
const struct compressionParameters* pThis,
|
|
|
|
const char* src, char* dst, int srcSize, int dstSize);
|
|
|
|
void (*cleanupFunction)(
|
|
|
|
const struct compressionParameters* pThis);
|
|
|
|
};
|
|
|
|
|
|
|
|
static void LZ4_compressInitNoStream(
|
|
|
|
struct compressionParameters* pThis)
|
|
|
|
{
|
|
|
|
pThis->LZ4_stream = NULL;
|
|
|
|
pThis->LZ4_dictStream = NULL;
|
|
|
|
pThis->LZ4_streamHC = NULL;
|
|
|
|
pThis->LZ4_dictStreamHC = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void LZ4_compressInitStream(
|
|
|
|
struct compressionParameters* pThis)
|
|
|
|
{
|
|
|
|
pThis->LZ4_stream = LZ4_createStream();
|
|
|
|
pThis->LZ4_dictStream = LZ4_createStream();
|
|
|
|
pThis->LZ4_streamHC = NULL;
|
|
|
|
pThis->LZ4_dictStreamHC = NULL;
|
|
|
|
LZ4_loadDict(pThis->LZ4_dictStream, pThis->dictBuf, pThis->dictSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void LZ4_compressInitStreamHC(
|
|
|
|
struct compressionParameters* pThis)
|
|
|
|
{
|
|
|
|
pThis->LZ4_stream = NULL;
|
|
|
|
pThis->LZ4_dictStream = NULL;
|
|
|
|
pThis->LZ4_streamHC = LZ4_createStreamHC();
|
|
|
|
pThis->LZ4_dictStreamHC = LZ4_createStreamHC();
|
|
|
|
LZ4_loadDictHC(pThis->LZ4_dictStreamHC, pThis->dictBuf, pThis->dictSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void LZ4_compressResetNoStream(
|
|
|
|
const struct compressionParameters* pThis)
|
|
|
|
{
|
|
|
|
(void)pThis;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void LZ4_compressResetStream(
|
|
|
|
const struct compressionParameters* pThis)
|
|
|
|
{
|
|
|
|
LZ4_resetStream_fast(pThis->LZ4_stream);
|
|
|
|
LZ4_attach_dictionary(pThis->LZ4_stream, pThis->LZ4_dictStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void LZ4_compressResetStreamHC(
|
|
|
|
const struct compressionParameters* pThis)
|
|
|
|
{
|
|
|
|
LZ4_resetStreamHC_fast(pThis->LZ4_streamHC, pThis->cLevel);
|
|
|
|
LZ4_attach_HC_dictionary(pThis->LZ4_streamHC, pThis->LZ4_dictStreamHC);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int LZ4_compressBlockNoStream(
|
|
|
|
const struct compressionParameters* pThis,
|
|
|
|
const char* src, char* dst,
|
|
|
|
int srcSize, int dstSize)
|
|
|
|
{
|
|
|
|
int const acceleration = (pThis->cLevel < 0) ? -pThis->cLevel + 1 : 1;
|
|
|
|
return LZ4_compress_fast(src, dst, srcSize, dstSize, acceleration);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int LZ4_compressBlockNoStreamHC(
|
|
|
|
const struct compressionParameters* pThis,
|
|
|
|
const char* src, char* dst,
|
|
|
|
int srcSize, int dstSize)
|
|
|
|
{
|
|
|
|
return LZ4_compress_HC(src, dst, srcSize, dstSize, pThis->cLevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int LZ4_compressBlockStream(
|
|
|
|
const struct compressionParameters* pThis,
|
|
|
|
const char* src, char* dst,
|
|
|
|
int srcSize, int dstSize)
|
|
|
|
{
|
|
|
|
int const acceleration = (pThis->cLevel < 0) ? -pThis->cLevel + 1 : 1;
|
|
|
|
return LZ4_compress_fast_continue(pThis->LZ4_stream, src, dst, srcSize, dstSize, acceleration);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int LZ4_compressBlockStreamHC(
|
|
|
|
const struct compressionParameters* pThis,
|
|
|
|
const char* src, char* dst,
|
|
|
|
int srcSize, int dstSize)
|
|
|
|
{
|
|
|
|
return LZ4_compress_HC_continue(pThis->LZ4_streamHC, src, dst, srcSize, dstSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void LZ4_compressCleanupNoStream(
|
|
|
|
const struct compressionParameters* pThis)
|
|
|
|
{
|
|
|
|
(void)pThis;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void LZ4_compressCleanupStream(
|
|
|
|
const struct compressionParameters* pThis)
|
|
|
|
{
|
|
|
|
LZ4_freeStream(pThis->LZ4_stream);
|
|
|
|
LZ4_freeStream(pThis->LZ4_dictStream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void LZ4_compressCleanupStreamHC(
|
|
|
|
const struct compressionParameters* pThis)
|
|
|
|
{
|
|
|
|
LZ4_freeStreamHC(pThis->LZ4_streamHC);
|
|
|
|
LZ4_freeStreamHC(pThis->LZ4_dictStreamHC);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void LZ4_buildCompressionParameters(
|
|
|
|
struct compressionParameters* pParams,
|
|
|
|
int cLevel, const char* dictBuf, int dictSize)
|
|
|
|
{
|
|
|
|
pParams->cLevel = cLevel;
|
|
|
|
pParams->dictBuf = dictBuf;
|
|
|
|
pParams->dictSize = dictSize;
|
|
|
|
|
|
|
|
if (dictSize) {
|
|
|
|
if (cLevel < LZ4HC_CLEVEL_MIN) {
|
|
|
|
pParams->initFunction = LZ4_compressInitStream;
|
|
|
|
pParams->resetFunction = LZ4_compressResetStream;
|
|
|
|
pParams->blockFunction = LZ4_compressBlockStream;
|
|
|
|
pParams->cleanupFunction = LZ4_compressCleanupStream;
|
|
|
|
} else {
|
|
|
|
pParams->initFunction = LZ4_compressInitStreamHC;
|
|
|
|
pParams->resetFunction = LZ4_compressResetStreamHC;
|
|
|
|
pParams->blockFunction = LZ4_compressBlockStreamHC;
|
|
|
|
pParams->cleanupFunction = LZ4_compressCleanupStreamHC;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pParams->initFunction = LZ4_compressInitNoStream;
|
|
|
|
pParams->resetFunction = LZ4_compressResetNoStream;
|
|
|
|
pParams->cleanupFunction = LZ4_compressCleanupNoStream;
|
|
|
|
|
|
|
|
if (cLevel < LZ4HC_CLEVEL_MIN) {
|
|
|
|
pParams->blockFunction = LZ4_compressBlockNoStream;
|
|
|
|
} else {
|
|
|
|
pParams->blockFunction = LZ4_compressBlockNoStreamHC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-09 23:04:55 +00:00
|
|
|
#define LZ4_isError(errcode) (errcode==0)
|
2013-12-30 17:16:52 +00:00
|
|
|
|
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
/* *************************************
|
|
|
|
* Constants
|
2014-12-16 21:03:16 +00:00
|
|
|
***************************************/
|
2016-11-04 13:26:12 +00:00
|
|
|
#ifndef LZ4_GIT_COMMIT_STRING
|
|
|
|
# define LZ4_GIT_COMMIT_STRING ""
|
2013-12-30 17:16:52 +00:00
|
|
|
#else
|
2016-11-04 13:26:12 +00:00
|
|
|
# define LZ4_GIT_COMMIT_STRING LZ4_EXPAND_AND_QUOTE(LZ4_GIT_COMMIT)
|
2013-12-30 17:16:52 +00:00
|
|
|
#endif
|
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
#define NBSECONDS 3
|
|
|
|
#define TIMELOOP_MICROSEC 1*1000000ULL /* 1 second */
|
2018-02-20 21:05:22 +00:00
|
|
|
#define TIMELOOP_NANOSEC 1*1000000000ULL /* 1 second */
|
2016-11-04 13:26:12 +00:00
|
|
|
#define ACTIVEPERIOD_MICROSEC 70*1000000ULL /* 70 seconds */
|
|
|
|
#define COOLPERIOD_SEC 10
|
2017-09-07 19:12:36 +00:00
|
|
|
#define DECOMP_MULT 1 /* test decompression DECOMP_MULT times longer than compression */
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2014-12-16 21:03:16 +00:00
|
|
|
#define KB *(1 <<10)
|
|
|
|
#define MB *(1 <<20)
|
2013-12-30 17:16:52 +00:00
|
|
|
#define GB *(1U<<30)
|
|
|
|
|
2019-11-04 19:51:41 +00:00
|
|
|
#define LZ4_MAX_DICT_SIZE (64 KB)
|
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
static const size_t maxMemory = (sizeof(size_t)==4) ? (2 GB - 64 MB) : (size_t)(1ULL << ((sizeof(size_t)*8)-31));
|
|
|
|
|
|
|
|
static U32 g_compressibilityDefault = 50;
|
2013-12-30 17:16:52 +00:00
|
|
|
|
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
/* *************************************
|
|
|
|
* console display
|
2014-12-16 21:03:16 +00:00
|
|
|
***************************************/
|
2016-11-04 13:26:12 +00:00
|
|
|
#define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
|
|
|
|
#define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); }
|
|
|
|
static U32 g_displayLevel = 2; /* 0 : no display; 1: errors; 2 : + result + interaction + warnings; 3 : + progression; 4 : + information */
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
#define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \
|
|
|
|
if ((clock() - g_time > refreshRate) || (g_displayLevel>=4)) \
|
|
|
|
{ g_time = clock(); DISPLAY(__VA_ARGS__); \
|
|
|
|
if (g_displayLevel>=4) fflush(stdout); } }
|
|
|
|
static const clock_t refreshRate = CLOCKS_PER_SEC * 15 / 100;
|
|
|
|
static clock_t g_time = 0;
|
2013-12-30 17:16:52 +00:00
|
|
|
|
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
/* *************************************
|
|
|
|
* Exceptions
|
2014-12-16 21:03:16 +00:00
|
|
|
***************************************/
|
2016-11-04 13:26:12 +00:00
|
|
|
#ifndef DEBUG
|
|
|
|
# define DEBUG 0
|
|
|
|
#endif
|
|
|
|
#define DEBUGOUTPUT(...) if (DEBUG) DISPLAY(__VA_ARGS__);
|
|
|
|
#define EXM_THROW(error, ...) \
|
|
|
|
{ \
|
|
|
|
DEBUGOUTPUT("Error defined at %s, line %i : \n", __FILE__, __LINE__); \
|
|
|
|
DISPLAYLEVEL(1, "Error %i : ", error); \
|
|
|
|
DISPLAYLEVEL(1, __VA_ARGS__); \
|
|
|
|
DISPLAYLEVEL(1, "\n"); \
|
|
|
|
exit(error); \
|
|
|
|
}
|
2013-12-30 17:16:52 +00:00
|
|
|
|
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
/* *************************************
|
2014-12-16 21:03:16 +00:00
|
|
|
* Benchmark Parameters
|
|
|
|
***************************************/
|
2016-11-04 13:26:12 +00:00
|
|
|
static U32 g_nbSeconds = NBSECONDS;
|
|
|
|
static size_t g_blockSize = 0;
|
|
|
|
int g_additionalParam = 0;
|
2018-03-20 00:19:25 +00:00
|
|
|
int g_benchSeparately = 0;
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
void BMK_setNotificationLevel(unsigned level) { g_displayLevel=level; }
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
void BMK_setAdditionalParam(int additionalParam) { g_additionalParam=additionalParam; }
|
|
|
|
|
2018-03-20 00:19:25 +00:00
|
|
|
void BMK_setNbSeconds(unsigned nbSeconds)
|
2013-12-30 17:16:52 +00:00
|
|
|
{
|
2016-11-04 13:26:12 +00:00
|
|
|
g_nbSeconds = nbSeconds;
|
|
|
|
DISPLAYLEVEL(3, "- test >= %u seconds per compression / decompression -\n", g_nbSeconds);
|
2013-12-30 17:16:52 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 00:19:25 +00:00
|
|
|
void BMK_setBlockSize(size_t blockSize) { g_blockSize = blockSize; }
|
|
|
|
|
|
|
|
void BMK_setBenchSeparately(int separate) { g_benchSeparately = (separate!=0); }
|
2013-12-30 17:16:52 +00:00
|
|
|
|
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
/* ********************************************************
|
|
|
|
* Bench functions
|
2014-12-16 21:03:16 +00:00
|
|
|
**********************************************************/
|
2016-11-09 23:04:55 +00:00
|
|
|
typedef struct {
|
2016-11-04 13:26:12 +00:00
|
|
|
const char* srcPtr;
|
|
|
|
size_t srcSize;
|
|
|
|
char* cPtr;
|
|
|
|
size_t cRoom;
|
|
|
|
size_t cSize;
|
|
|
|
char* resPtr;
|
|
|
|
size_t resSize;
|
|
|
|
} blockParam_t;
|
|
|
|
|
|
|
|
#define MIN(a,b) ((a)<(b) ? (a) : (b))
|
|
|
|
#define MAX(a,b) ((a)>(b) ? (a) : (b))
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
|
|
|
const char* displayName, int cLevel,
|
2019-11-04 19:51:41 +00:00
|
|
|
const size_t* fileSizes, U32 nbFiles,
|
|
|
|
const char* dictBuf, int dictSize)
|
2013-12-30 17:16:52 +00:00
|
|
|
{
|
2016-11-04 13:26:12 +00:00
|
|
|
size_t const blockSize = (g_blockSize>=32 ? g_blockSize : srcSize) + (!srcSize) /* avoid div by 0 */ ;
|
|
|
|
U32 const maxNbBlocks = (U32) ((srcSize + (blockSize-1)) / blockSize) + nbFiles;
|
|
|
|
blockParam_t* const blockTable = (blockParam_t*) malloc(maxNbBlocks * sizeof(blockParam_t));
|
|
|
|
size_t const maxCompressedSize = LZ4_compressBound((int)srcSize) + (maxNbBlocks * 1024); /* add some room for safety */
|
|
|
|
void* const compressedBuffer = malloc(maxCompressedSize);
|
|
|
|
void* const resultBuffer = malloc(srcSize);
|
|
|
|
U32 nbBlocks;
|
|
|
|
struct compressionParameters compP;
|
|
|
|
|
|
|
|
/* checks */
|
|
|
|
if (!compressedBuffer || !resultBuffer || !blockTable)
|
|
|
|
EXM_THROW(31, "allocation error : not enough memory");
|
|
|
|
|
|
|
|
if (strlen(displayName)>17) displayName += strlen(displayName)-17; /* can only display 17 characters */
|
|
|
|
|
2019-11-04 19:51:41 +00:00
|
|
|
/* init */
|
|
|
|
LZ4_buildCompressionParameters(&compP, cLevel, dictBuf, dictSize);
|
|
|
|
compP.initFunction(&compP);
|
2016-11-04 13:26:12 +00:00
|
|
|
|
|
|
|
/* Init blockTable data */
|
|
|
|
{ const char* srcPtr = (const char*)srcBuffer;
|
|
|
|
char* cPtr = (char*)compressedBuffer;
|
|
|
|
char* resPtr = (char*)resultBuffer;
|
|
|
|
U32 fileNb;
|
|
|
|
for (nbBlocks=0, fileNb=0; fileNb<nbFiles; fileNb++) {
|
|
|
|
size_t remaining = fileSizes[fileNb];
|
|
|
|
U32 const nbBlocksforThisFile = (U32)((remaining + (blockSize-1)) / blockSize);
|
|
|
|
U32 const blockEnd = nbBlocks + nbBlocksforThisFile;
|
|
|
|
for ( ; nbBlocks<blockEnd; nbBlocks++) {
|
|
|
|
size_t const thisBlockSize = MIN(remaining, blockSize);
|
|
|
|
blockTable[nbBlocks].srcPtr = srcPtr;
|
|
|
|
blockTable[nbBlocks].cPtr = cPtr;
|
|
|
|
blockTable[nbBlocks].resPtr = resPtr;
|
|
|
|
blockTable[nbBlocks].srcSize = thisBlockSize;
|
2019-04-18 19:05:50 +00:00
|
|
|
blockTable[nbBlocks].cRoom = (size_t)LZ4_compressBound((int)thisBlockSize);
|
2016-11-04 13:26:12 +00:00
|
|
|
srcPtr += thisBlockSize;
|
|
|
|
cPtr += blockTable[nbBlocks].cRoom;
|
|
|
|
resPtr += thisBlockSize;
|
|
|
|
remaining -= thisBlockSize;
|
|
|
|
} } }
|
|
|
|
|
|
|
|
/* warmimg up memory */
|
|
|
|
RDG_genBuffer(compressedBuffer, maxCompressedSize, 0.10, 0.50, 1);
|
|
|
|
|
|
|
|
/* Bench */
|
|
|
|
{ U64 fastestC = (U64)(-1LL), fastestD = (U64)(-1LL);
|
|
|
|
U64 const crcOrig = XXH64(srcBuffer, srcSize, 0);
|
|
|
|
UTIL_time_t coolTime;
|
2018-02-20 21:05:22 +00:00
|
|
|
U64 const maxTime = (g_nbSeconds * TIMELOOP_NANOSEC) + 100;
|
2018-02-20 22:13:13 +00:00
|
|
|
U32 nbCompressionLoops = (U32)((5 MB) / (srcSize+1)) + 1; /* conservative initial compression speed estimate */
|
|
|
|
U32 nbDecodeLoops = (U32)((200 MB) / (srcSize+1)) + 1; /* conservative initial decode speed estimate */
|
2016-11-04 13:26:12 +00:00
|
|
|
U64 totalCTime=0, totalDTime=0;
|
|
|
|
U32 cCompleted=0, dCompleted=0;
|
|
|
|
# define NB_MARKS 4
|
|
|
|
const char* const marks[NB_MARKS] = { " |", " /", " =", "\\" };
|
|
|
|
U32 markNb = 0;
|
|
|
|
size_t cSize = 0;
|
|
|
|
double ratio = 0.;
|
|
|
|
|
2017-10-17 19:42:27 +00:00
|
|
|
coolTime = UTIL_getTime();
|
2016-11-04 13:26:12 +00:00
|
|
|
DISPLAYLEVEL(2, "\r%79s\r", "");
|
2017-01-12 16:43:25 +00:00
|
|
|
while (!cCompleted || !dCompleted) {
|
2016-11-04 13:26:12 +00:00
|
|
|
/* overheat protection */
|
2017-10-17 19:42:27 +00:00
|
|
|
if (UTIL_clockSpanMicro(coolTime) > ACTIVEPERIOD_MICROSEC) {
|
2016-11-04 13:26:12 +00:00
|
|
|
DISPLAYLEVEL(2, "\rcooling down ... \r");
|
|
|
|
UTIL_sleep(COOLPERIOD_SEC);
|
2017-10-17 19:42:27 +00:00
|
|
|
coolTime = UTIL_getTime();
|
2016-11-04 13:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Compression */
|
|
|
|
DISPLAYLEVEL(2, "%2s-%-17.17s :%10u ->\r", marks[markNb], displayName, (U32)srcSize);
|
|
|
|
if (!cCompleted) memset(compressedBuffer, 0xE5, maxCompressedSize); /* warm up and erase result buffer */
|
|
|
|
|
|
|
|
UTIL_sleepMilli(1); /* give processor time to other processes */
|
2017-10-17 19:42:27 +00:00
|
|
|
UTIL_waitForNextTick();
|
2016-11-04 13:26:12 +00:00
|
|
|
|
|
|
|
if (!cCompleted) { /* still some time to do compression tests */
|
2018-02-20 21:05:22 +00:00
|
|
|
UTIL_time_t const clockStart = UTIL_getTime();
|
|
|
|
U32 nbLoops;
|
|
|
|
for (nbLoops=0; nbLoops < nbCompressionLoops; nbLoops++) {
|
2016-11-04 13:26:12 +00:00
|
|
|
U32 blockNb;
|
2019-11-04 19:51:41 +00:00
|
|
|
compP.resetFunction(&compP);
|
2016-11-04 13:26:12 +00:00
|
|
|
for (blockNb=0; blockNb<nbBlocks; blockNb++) {
|
2019-11-04 19:51:41 +00:00
|
|
|
size_t const rSize = (size_t)compP.blockFunction(
|
|
|
|
&compP,
|
|
|
|
blockTable[blockNb].srcPtr, blockTable[blockNb].cPtr,
|
|
|
|
(int)blockTable[blockNb].srcSize, (int)blockTable[blockNb].cRoom);
|
2019-04-18 19:05:50 +00:00
|
|
|
if (LZ4_isError(rSize)) EXM_THROW(1, "LZ4 compression failed");
|
2016-11-04 13:26:12 +00:00
|
|
|
blockTable[blockNb].cSize = rSize;
|
2018-02-20 21:05:22 +00:00
|
|
|
} }
|
|
|
|
{ U64 const clockSpan = UTIL_clockSpanNano(clockStart);
|
|
|
|
if (clockSpan > 0) {
|
|
|
|
if (clockSpan < fastestC * nbCompressionLoops)
|
|
|
|
fastestC = clockSpan / nbCompressionLoops;
|
|
|
|
assert(fastestC > 0);
|
2018-02-20 23:26:59 +00:00
|
|
|
nbCompressionLoops = (U32)(TIMELOOP_NANOSEC / fastestC) + 1; /* aim for ~1sec */
|
2018-02-20 21:05:22 +00:00
|
|
|
} else {
|
|
|
|
assert(nbCompressionLoops < 40000000); /* avoid overflow */
|
|
|
|
nbCompressionLoops *= 100;
|
2016-11-04 13:26:12 +00:00
|
|
|
}
|
|
|
|
totalCTime += clockSpan;
|
|
|
|
cCompleted = totalCTime>maxTime;
|
|
|
|
} }
|
|
|
|
|
|
|
|
cSize = 0;
|
|
|
|
{ U32 blockNb; for (blockNb=0; blockNb<nbBlocks; blockNb++) cSize += blockTable[blockNb].cSize; }
|
2016-11-15 22:01:37 +00:00
|
|
|
cSize += !cSize; /* avoid div by 0 */
|
2016-11-04 13:26:12 +00:00
|
|
|
ratio = (double)srcSize / (double)cSize;
|
|
|
|
markNb = (markNb+1) % NB_MARKS;
|
|
|
|
DISPLAYLEVEL(2, "%2s-%-17.17s :%10u ->%10u (%5.3f),%6.1f MB/s\r",
|
|
|
|
marks[markNb], displayName, (U32)srcSize, (U32)cSize, ratio,
|
2018-02-20 21:05:22 +00:00
|
|
|
((double)srcSize / fastestC) * 1000 );
|
2016-11-04 13:26:12 +00:00
|
|
|
|
|
|
|
(void)fastestD; (void)crcOrig; /* unused when decompression disabled */
|
|
|
|
#if 1
|
|
|
|
/* Decompression */
|
|
|
|
if (!dCompleted) memset(resultBuffer, 0xD6, srcSize); /* warm result buffer */
|
|
|
|
|
2018-02-20 19:37:19 +00:00
|
|
|
UTIL_sleepMilli(5); /* give processor time to other processes */
|
2017-10-17 19:42:27 +00:00
|
|
|
UTIL_waitForNextTick();
|
2016-11-04 13:26:12 +00:00
|
|
|
|
|
|
|
if (!dCompleted) {
|
2018-02-20 21:05:22 +00:00
|
|
|
UTIL_time_t const clockStart = UTIL_getTime();
|
2018-02-20 19:37:19 +00:00
|
|
|
U32 nbLoops;
|
|
|
|
for (nbLoops=0; nbLoops < nbDecodeLoops; nbLoops++) {
|
2016-11-04 13:26:12 +00:00
|
|
|
U32 blockNb;
|
|
|
|
for (blockNb=0; blockNb<nbBlocks; blockNb++) {
|
2019-11-04 19:51:41 +00:00
|
|
|
int const regenSize = LZ4_decompress_safe_usingDict(
|
|
|
|
blockTable[blockNb].cPtr, blockTable[blockNb].resPtr,
|
|
|
|
(int)blockTable[blockNb].cSize, (int)blockTable[blockNb].srcSize,
|
|
|
|
dictBuf, dictSize);
|
2019-04-18 19:05:50 +00:00
|
|
|
if (regenSize < 0) {
|
2019-11-04 19:51:41 +00:00
|
|
|
DISPLAY("LZ4_decompress_safe_usingDict() failed on block %u \n", blockNb);
|
2016-11-04 13:26:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-04-18 19:05:50 +00:00
|
|
|
blockTable[blockNb].resSize = (size_t)regenSize;
|
2018-02-20 19:37:19 +00:00
|
|
|
} }
|
2018-02-20 21:05:22 +00:00
|
|
|
{ U64 const clockSpan = UTIL_clockSpanNano(clockStart);
|
|
|
|
if (clockSpan > 0) {
|
|
|
|
if (clockSpan < fastestD * nbDecodeLoops)
|
|
|
|
fastestD = clockSpan / nbDecodeLoops;
|
|
|
|
assert(fastestD > 0);
|
2018-02-20 23:26:59 +00:00
|
|
|
nbDecodeLoops = (U32)(TIMELOOP_NANOSEC / fastestD) + 1; /* aim for ~1sec */
|
2018-02-20 21:05:22 +00:00
|
|
|
} else {
|
|
|
|
assert(nbDecodeLoops < 40000000); /* avoid overflow */
|
|
|
|
nbDecodeLoops *= 100;
|
|
|
|
}
|
2016-11-04 13:26:12 +00:00
|
|
|
totalDTime += clockSpan;
|
2018-02-20 19:37:19 +00:00
|
|
|
dCompleted = totalDTime > (DECOMP_MULT*maxTime);
|
2016-11-04 13:26:12 +00:00
|
|
|
} }
|
|
|
|
|
|
|
|
markNb = (markNb+1) % NB_MARKS;
|
|
|
|
DISPLAYLEVEL(2, "%2s-%-17.17s :%10u ->%10u (%5.3f),%6.1f MB/s ,%6.1f MB/s\r",
|
|
|
|
marks[markNb], displayName, (U32)srcSize, (U32)cSize, ratio,
|
2018-02-20 21:05:22 +00:00
|
|
|
((double)srcSize / fastestC) * 1000,
|
|
|
|
((double)srcSize / fastestD) * 1000);
|
2016-11-04 13:26:12 +00:00
|
|
|
|
|
|
|
/* CRC Checking */
|
|
|
|
{ U64 const crcCheck = XXH64(resultBuffer, srcSize, 0);
|
|
|
|
if (crcOrig!=crcCheck) {
|
|
|
|
size_t u;
|
2018-09-05 01:21:40 +00:00
|
|
|
DISPLAY("\n!!! WARNING !!! %17s : Invalid Checksum : %x != %x \n", displayName, (unsigned)crcOrig, (unsigned)crcCheck);
|
2016-11-04 13:26:12 +00:00
|
|
|
for (u=0; u<srcSize; u++) {
|
|
|
|
if (((const BYTE*)srcBuffer)[u] != ((const BYTE*)resultBuffer)[u]) {
|
|
|
|
U32 segNb, bNb, pos;
|
|
|
|
size_t bacc = 0;
|
|
|
|
DISPLAY("Decoding error at pos %u ", (U32)u);
|
|
|
|
for (segNb = 0; segNb < nbBlocks; segNb++) {
|
|
|
|
if (bacc + blockTable[segNb].srcSize > u) break;
|
|
|
|
bacc += blockTable[segNb].srcSize;
|
|
|
|
}
|
|
|
|
pos = (U32)(u - bacc);
|
|
|
|
bNb = pos / (128 KB);
|
|
|
|
DISPLAY("(block %u, sub %u, pos %u) \n", segNb, bNb, pos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (u==srcSize-1) { /* should never happen */
|
|
|
|
DISPLAY("no difference detected\n");
|
|
|
|
} }
|
|
|
|
break;
|
|
|
|
} } /* CRC Checking */
|
|
|
|
#endif
|
|
|
|
} /* for (testNb = 1; testNb <= (g_nbSeconds + !g_nbSeconds); testNb++) */
|
|
|
|
|
|
|
|
if (g_displayLevel == 1) {
|
2018-02-20 21:05:22 +00:00
|
|
|
double const cSpeed = ((double)srcSize / fastestC) * 1000;
|
|
|
|
double const dSpeed = ((double)srcSize / fastestD) * 1000;
|
2016-11-04 13:26:12 +00:00
|
|
|
if (g_additionalParam)
|
|
|
|
DISPLAY("-%-3i%11i (%5.3f) %6.2f MB/s %6.1f MB/s %s (param=%d)\n", cLevel, (int)cSize, ratio, cSpeed, dSpeed, displayName, g_additionalParam);
|
|
|
|
else
|
|
|
|
DISPLAY("-%-3i%11i (%5.3f) %6.2f MB/s %6.1f MB/s %s\n", cLevel, (int)cSize, ratio, cSpeed, dSpeed, displayName);
|
|
|
|
}
|
|
|
|
DISPLAYLEVEL(2, "%2i#\n", cLevel);
|
|
|
|
} /* Bench */
|
|
|
|
|
|
|
|
/* clean up */
|
2019-11-04 19:51:41 +00:00
|
|
|
compP.cleanupFunction(&compP);
|
2016-11-04 13:26:12 +00:00
|
|
|
free(blockTable);
|
|
|
|
free(compressedBuffer);
|
|
|
|
free(resultBuffer);
|
|
|
|
return 0;
|
2013-12-30 17:16:52 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
|
2013-12-30 17:16:52 +00:00
|
|
|
static size_t BMK_findMaxMem(U64 requiredMem)
|
|
|
|
{
|
2016-11-04 15:56:01 +00:00
|
|
|
size_t step = 64 MB;
|
|
|
|
BYTE* testmem=NULL;
|
2013-12-30 17:16:52 +00:00
|
|
|
|
|
|
|
requiredMem = (((requiredMem >> 26) + 1) << 26);
|
2016-11-04 15:56:01 +00:00
|
|
|
requiredMem += 2*step;
|
2016-11-04 13:26:12 +00:00
|
|
|
if (requiredMem > maxMemory) requiredMem = maxMemory;
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2016-11-04 15:56:01 +00:00
|
|
|
while (!testmem) {
|
|
|
|
if (requiredMem > step) requiredMem -= step;
|
|
|
|
else requiredMem >>= 1;
|
|
|
|
testmem = (BYTE*) malloc ((size_t)requiredMem);
|
|
|
|
}
|
|
|
|
free (testmem);
|
|
|
|
|
|
|
|
/* keep some space available */
|
|
|
|
if (requiredMem > step) requiredMem -= step;
|
|
|
|
else requiredMem >>= 1;
|
2015-03-15 00:42:27 +00:00
|
|
|
|
2016-11-04 15:56:01 +00:00
|
|
|
return (size_t)requiredMem;
|
2013-12-30 17:16:52 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 15:56:01 +00:00
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
static void BMK_benchCLevel(void* srcBuffer, size_t benchedSize,
|
|
|
|
const char* displayName, int cLevel, int cLevelLast,
|
2019-11-04 19:51:41 +00:00
|
|
|
const size_t* fileSizes, unsigned nbFiles,
|
|
|
|
const char* dictBuf, int dictSize)
|
2013-12-30 17:16:52 +00:00
|
|
|
{
|
2016-11-04 13:26:12 +00:00
|
|
|
int l;
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
const char* pch = strrchr(displayName, '\\'); /* Windows */
|
|
|
|
if (!pch) pch = strrchr(displayName, '/'); /* Linux */
|
|
|
|
if (pch) displayName = pch+1;
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2017-02-15 16:16:15 +00:00
|
|
|
SET_REALTIME_PRIORITY;
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
if (g_displayLevel == 1 && !g_additionalParam)
|
|
|
|
DISPLAY("bench %s %s: input %u bytes, %u seconds, %u KB blocks\n", LZ4_VERSION_STRING, LZ4_GIT_COMMIT_STRING, (U32)benchedSize, g_nbSeconds, (U32)(g_blockSize>>10));
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2018-06-27 00:31:15 +00:00
|
|
|
if (cLevelLast < cLevel) cLevelLast = cLevel;
|
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
for (l=cLevel; l <= cLevelLast; l++) {
|
|
|
|
BMK_benchMem(srcBuffer, benchedSize,
|
|
|
|
displayName, l,
|
2019-11-04 19:51:41 +00:00
|
|
|
fileSizes, nbFiles,
|
|
|
|
dictBuf, dictSize);
|
2016-11-04 13:26:12 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-30 17:16:52 +00:00
|
|
|
|
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
/*! BMK_loadFiles() :
|
|
|
|
Loads `buffer` with content of files listed within `fileNamesTable`.
|
|
|
|
At most, fills `buffer` entirely */
|
|
|
|
static void BMK_loadFiles(void* buffer, size_t bufferSize,
|
|
|
|
size_t* fileSizes,
|
|
|
|
const char** fileNamesTable, unsigned nbFiles)
|
|
|
|
{
|
|
|
|
size_t pos = 0, totalSize = 0;
|
|
|
|
unsigned n;
|
|
|
|
for (n=0; n<nbFiles; n++) {
|
|
|
|
FILE* f;
|
|
|
|
U64 fileSize = UTIL_getFileSize(fileNamesTable[n]);
|
|
|
|
if (UTIL_isDirectory(fileNamesTable[n])) {
|
|
|
|
DISPLAYLEVEL(2, "Ignoring %s directory... \n", fileNamesTable[n]);
|
|
|
|
fileSizes[n] = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
f = fopen(fileNamesTable[n], "rb");
|
|
|
|
if (f==NULL) EXM_THROW(10, "impossible to open file %s", fileNamesTable[n]);
|
|
|
|
DISPLAYUPDATE(2, "Loading %s... \r", fileNamesTable[n]);
|
2017-09-10 21:32:38 +00:00
|
|
|
if (fileSize > bufferSize-pos) { /* buffer too small - stop after this file */
|
|
|
|
fileSize = bufferSize-pos;
|
|
|
|
nbFiles=n;
|
|
|
|
}
|
2016-11-04 13:26:12 +00:00
|
|
|
{ size_t const readSize = fread(((char*)buffer)+pos, 1, (size_t)fileSize, f);
|
|
|
|
if (readSize != (size_t)fileSize) EXM_THROW(11, "could not read %s", fileNamesTable[n]);
|
|
|
|
pos += readSize; }
|
|
|
|
fileSizes[n] = (size_t)fileSize;
|
|
|
|
totalSize += (size_t)fileSize;
|
|
|
|
fclose(f);
|
|
|
|
}
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
if (totalSize == 0) EXM_THROW(12, "no data to bench");
|
2013-12-30 17:16:52 +00:00
|
|
|
}
|
2016-09-02 20:59:18 +00:00
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
static void BMK_benchFileTable(const char** fileNamesTable, unsigned nbFiles,
|
2019-11-04 19:51:41 +00:00
|
|
|
int cLevel, int cLevelLast,
|
|
|
|
const char* dictBuf, int dictSize)
|
2016-11-04 13:26:12 +00:00
|
|
|
{
|
|
|
|
void* srcBuffer;
|
|
|
|
size_t benchedSize;
|
|
|
|
size_t* fileSizes = (size_t*)malloc(nbFiles * sizeof(size_t));
|
|
|
|
U64 const totalSizeToLoad = UTIL_getTotalFileSize(fileNamesTable, nbFiles);
|
|
|
|
char mfName[20] = {0};
|
|
|
|
|
|
|
|
if (!fileSizes) EXM_THROW(12, "not enough memory for fileSizes");
|
|
|
|
|
|
|
|
/* Memory allocation & restrictions */
|
|
|
|
benchedSize = BMK_findMaxMem(totalSizeToLoad * 3) / 3;
|
|
|
|
if (benchedSize==0) EXM_THROW(12, "not enough memory");
|
|
|
|
if ((U64)benchedSize > totalSizeToLoad) benchedSize = (size_t)totalSizeToLoad;
|
2017-03-10 19:49:25 +00:00
|
|
|
if (benchedSize > LZ4_MAX_INPUT_SIZE) {
|
2017-09-07 19:12:36 +00:00
|
|
|
benchedSize = LZ4_MAX_INPUT_SIZE;
|
2017-03-10 19:49:25 +00:00
|
|
|
DISPLAY("File(s) bigger than LZ4's max input size; testing %u MB only...\n", (U32)(benchedSize >> 20));
|
2017-09-07 19:12:36 +00:00
|
|
|
} else {
|
2017-03-10 19:49:25 +00:00
|
|
|
if (benchedSize < totalSizeToLoad)
|
|
|
|
DISPLAY("Not enough memory; testing %u MB only...\n", (U32)(benchedSize >> 20));
|
|
|
|
}
|
2016-11-10 01:39:53 +00:00
|
|
|
srcBuffer = malloc(benchedSize + !benchedSize); /* avoid alloc of zero */
|
2016-11-04 13:26:12 +00:00
|
|
|
if (!srcBuffer) EXM_THROW(12, "not enough memory");
|
|
|
|
|
|
|
|
/* Load input buffer */
|
|
|
|
BMK_loadFiles(srcBuffer, benchedSize, fileSizes, fileNamesTable, nbFiles);
|
|
|
|
|
|
|
|
/* Bench */
|
|
|
|
snprintf (mfName, sizeof(mfName), " %u files", nbFiles);
|
|
|
|
{ const char* displayName = (nbFiles > 1) ? mfName : fileNamesTable[0];
|
|
|
|
BMK_benchCLevel(srcBuffer, benchedSize,
|
|
|
|
displayName, cLevel, cLevelLast,
|
2019-11-04 19:51:41 +00:00
|
|
|
fileSizes, nbFiles,
|
|
|
|
dictBuf, dictSize);
|
2016-11-04 13:26:12 +00:00
|
|
|
}
|
2016-09-02 20:59:18 +00:00
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
/* clean up */
|
|
|
|
free(srcBuffer);
|
|
|
|
free(fileSizes);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-04 19:51:41 +00:00
|
|
|
static void BMK_syntheticTest(int cLevel, int cLevelLast, double compressibility,
|
|
|
|
const char* dictBuf, int dictSize)
|
2016-09-02 20:59:18 +00:00
|
|
|
{
|
2016-11-04 13:26:12 +00:00
|
|
|
char name[20] = {0};
|
|
|
|
size_t benchedSize = 10000000;
|
|
|
|
void* const srcBuffer = malloc(benchedSize);
|
2016-09-02 20:59:18 +00:00
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
/* Memory allocation */
|
|
|
|
if (!srcBuffer) EXM_THROW(21, "not enough memory");
|
2016-09-02 20:59:18 +00:00
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
/* Fill input buffer */
|
|
|
|
RDG_genBuffer(srcBuffer, benchedSize, compressibility, 0.0, 0);
|
|
|
|
|
|
|
|
/* Bench */
|
|
|
|
snprintf (name, sizeof(name), "Synthetic %2u%%", (unsigned)(compressibility*100));
|
2019-11-04 19:51:41 +00:00
|
|
|
BMK_benchCLevel(srcBuffer, benchedSize, name, cLevel, cLevelLast, &benchedSize, 1, dictBuf, dictSize);
|
2016-11-04 13:26:12 +00:00
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
free(srcBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-20 00:19:25 +00:00
|
|
|
int BMK_benchFilesSeparately(const char** fileNamesTable, unsigned nbFiles,
|
2019-11-04 19:51:41 +00:00
|
|
|
int cLevel, int cLevelLast,
|
|
|
|
const char* dictBuf, int dictSize)
|
2018-03-20 00:19:25 +00:00
|
|
|
{
|
|
|
|
unsigned fileNb;
|
|
|
|
if (cLevel > LZ4HC_CLEVEL_MAX) cLevel = LZ4HC_CLEVEL_MAX;
|
|
|
|
if (cLevelLast > LZ4HC_CLEVEL_MAX) cLevelLast = LZ4HC_CLEVEL_MAX;
|
|
|
|
if (cLevelLast < cLevel) cLevelLast = cLevel;
|
|
|
|
if (cLevelLast > cLevel) DISPLAYLEVEL(2, "Benchmarking levels from %d to %d\n", cLevel, cLevelLast);
|
|
|
|
|
|
|
|
for (fileNb=0; fileNb<nbFiles; fileNb++)
|
2019-11-04 19:51:41 +00:00
|
|
|
BMK_benchFileTable(fileNamesTable+fileNb, 1, cLevel, cLevelLast, dictBuf, dictSize);
|
2018-03-20 00:19:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles,
|
2019-11-04 19:51:41 +00:00
|
|
|
int cLevel, int cLevelLast,
|
|
|
|
const char* dictFileName)
|
2016-11-04 13:26:12 +00:00
|
|
|
{
|
|
|
|
double const compressibility = (double)g_compressibilityDefault / 100;
|
2019-11-04 19:51:41 +00:00
|
|
|
char* dictBuf = NULL;
|
|
|
|
int dictSize = 0;
|
2016-09-03 02:32:06 +00:00
|
|
|
|
2016-12-22 10:41:05 +00:00
|
|
|
if (cLevel > LZ4HC_CLEVEL_MAX) cLevel = LZ4HC_CLEVEL_MAX;
|
|
|
|
if (cLevelLast > LZ4HC_CLEVEL_MAX) cLevelLast = LZ4HC_CLEVEL_MAX;
|
2016-11-10 15:31:10 +00:00
|
|
|
if (cLevelLast < cLevel) cLevelLast = cLevel;
|
|
|
|
if (cLevelLast > cLevel) DISPLAYLEVEL(2, "Benchmarking levels from %d to %d\n", cLevel, cLevelLast);
|
|
|
|
|
2019-11-04 19:51:41 +00:00
|
|
|
if (dictFileName) {
|
|
|
|
FILE* dictFile = NULL;
|
|
|
|
U64 dictFileSize = UTIL_getFileSize(dictFileName);
|
|
|
|
if (!dictFileSize) EXM_THROW(25, "Dictionary error : could not stat dictionary file");
|
|
|
|
|
|
|
|
dictFile = fopen(dictFileName, "rb");
|
|
|
|
if (!dictFile) EXM_THROW(25, "Dictionary error : could not open dictionary file");
|
|
|
|
|
|
|
|
if (dictFileSize > LZ4_MAX_DICT_SIZE) {
|
|
|
|
dictSize = LZ4_MAX_DICT_SIZE;
|
|
|
|
if (UTIL_fseek(dictFile, dictFileSize - dictSize, SEEK_SET))
|
|
|
|
EXM_THROW(25, "Dictionary error : could not seek dictionary file");
|
|
|
|
} else {
|
|
|
|
dictSize = (int)dictFileSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
dictBuf = (char *)malloc(dictSize);
|
|
|
|
if (!dictBuf) EXM_THROW(25, "Allocation error : not enough memory");
|
|
|
|
|
|
|
|
if (fread(dictBuf, 1, dictSize, dictFile) != (size_t)dictSize)
|
|
|
|
EXM_THROW(25, "Dictionary error : could not read dictionary file");
|
|
|
|
|
|
|
|
fclose(dictFile);
|
|
|
|
}
|
|
|
|
|
2016-11-04 13:26:12 +00:00
|
|
|
if (nbFiles == 0)
|
2019-11-04 19:51:41 +00:00
|
|
|
BMK_syntheticTest(cLevel, cLevelLast, compressibility, dictBuf, dictSize);
|
2018-03-20 00:19:25 +00:00
|
|
|
else {
|
|
|
|
if (g_benchSeparately)
|
2019-11-04 19:51:41 +00:00
|
|
|
BMK_benchFilesSeparately(fileNamesTable, nbFiles, cLevel, cLevelLast, dictBuf, dictSize);
|
2018-03-20 00:19:25 +00:00
|
|
|
else
|
2019-11-04 19:51:41 +00:00
|
|
|
BMK_benchFileTable(fileNamesTable, nbFiles, cLevel, cLevelLast, dictBuf, dictSize);
|
2018-03-20 00:19:25 +00:00
|
|
|
}
|
2019-11-04 19:51:41 +00:00
|
|
|
|
|
|
|
free(dictBuf);
|
2016-11-04 13:26:12 +00:00
|
|
|
return 0;
|
2016-09-02 20:59:18 +00:00
|
|
|
}
|