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
|
2016-06-29 15:48:28 +00:00
|
|
|
Copyright (C) Yann Collet 2012-2016
|
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
|
2015-03-13 01:24:08 +00:00
|
|
|
- LZ4 source repository : https://github.com/Cyan4973/lz4
|
2013-12-30 17:16:52 +00:00
|
|
|
*/
|
|
|
|
|
2016-06-29 11:43:11 +00:00
|
|
|
/*-************************************
|
2014-12-16 21:03:16 +00:00
|
|
|
* Compiler Options
|
|
|
|
***************************************/
|
2015-03-23 01:20:42 +00:00
|
|
|
#if defined(_MSC_VER) || defined(_WIN32)
|
|
|
|
# define _CRT_SECURE_NO_WARNINGS
|
|
|
|
# define _CRT_SECURE_NO_DEPRECATE /* VS2005 */
|
|
|
|
#endif
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2014-12-16 21:03:16 +00:00
|
|
|
/* Unix Large Files support (>4GB) */
|
2013-12-30 17:16:52 +00:00
|
|
|
#define _FILE_OFFSET_BITS 64
|
2014-12-16 21:03:16 +00:00
|
|
|
#if (defined(__sun__) && (!defined(__LP64__))) /* Sun Solaris 32-bits requires specific definitions */
|
2014-07-14 22:29:40 +00:00
|
|
|
# define _LARGEFILE_SOURCE
|
2014-12-16 21:03:16 +00:00
|
|
|
#elif ! defined(__LP64__) /* No point defining Large file for 64 bit */
|
2013-12-30 17:16:52 +00:00
|
|
|
# define _LARGEFILE64_SOURCE
|
|
|
|
#endif
|
|
|
|
|
2016-09-02 19:50:57 +00:00
|
|
|
#if defined(__MINGW32__) && !defined(_POSIX_SOURCE)
|
|
|
|
# define _POSIX_SOURCE 1 /* disable %llu warnings with MinGW on Windows */
|
|
|
|
#endif
|
|
|
|
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2016-06-29 11:43:11 +00:00
|
|
|
/*-************************************
|
2014-12-16 21:03:16 +00:00
|
|
|
* Includes
|
|
|
|
***************************************/
|
2016-06-29 12:35:19 +00:00
|
|
|
#include <stdlib.h> /* malloc */
|
|
|
|
#include <stdio.h> /* fprintf, fopen */
|
|
|
|
#include <sys/types.h> /* stat64 */
|
|
|
|
#include <sys/stat.h> /* stat64 */
|
|
|
|
#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */
|
2016-09-02 21:02:30 +00:00
|
|
|
#include <string.h> /* strlen */
|
|
|
|
|
2013-12-30 17:16:52 +00:00
|
|
|
|
|
|
|
#include "lz4.h"
|
2014-02-04 14:11:10 +00:00
|
|
|
#define COMPRESSOR0 LZ4_compress_local
|
2015-05-03 16:57:46 +00:00
|
|
|
static int LZ4_compress_local(const char* src, char* dst, int srcSize, int dstSize, int clevel) { (void)clevel; return LZ4_compress_default(src, dst, srcSize, dstSize); }
|
2013-12-30 17:16:52 +00:00
|
|
|
#include "lz4hc.h"
|
2015-05-03 19:57:21 +00:00
|
|
|
#define COMPRESSOR1 LZ4_compress_HC
|
2013-12-30 17:16:52 +00:00
|
|
|
#define DEFAULTCOMPRESSOR COMPRESSOR0
|
|
|
|
|
|
|
|
#include "xxhash.h"
|
|
|
|
|
|
|
|
|
2016-06-29 11:43:11 +00:00
|
|
|
/*-************************************
|
2014-12-16 21:03:16 +00:00
|
|
|
* Compiler specifics
|
|
|
|
***************************************/
|
2013-12-30 17:16:52 +00:00
|
|
|
#if !defined(S_ISREG)
|
|
|
|
# define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-06-29 11:43:11 +00:00
|
|
|
/*-************************************
|
2014-12-16 21:03:16 +00:00
|
|
|
* Basic Types
|
|
|
|
***************************************/
|
2014-12-17 11:20:17 +00:00
|
|
|
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
|
2013-12-30 17:16:52 +00:00
|
|
|
# include <stdint.h>
|
|
|
|
typedef uint8_t BYTE;
|
|
|
|
typedef uint16_t U16;
|
|
|
|
typedef uint32_t U32;
|
|
|
|
typedef int32_t S32;
|
|
|
|
typedef uint64_t U64;
|
|
|
|
#else
|
|
|
|
typedef unsigned char BYTE;
|
|
|
|
typedef unsigned short U16;
|
|
|
|
typedef unsigned int U32;
|
|
|
|
typedef signed int S32;
|
|
|
|
typedef unsigned long long U64;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-06-29 11:43:11 +00:00
|
|
|
/*-************************************
|
2014-12-16 21:03:16 +00:00
|
|
|
* Constants
|
|
|
|
***************************************/
|
2013-12-30 17:16:52 +00:00
|
|
|
#define NBLOOPS 3
|
2016-06-29 12:35:19 +00:00
|
|
|
#define TIMELOOP_S 1
|
|
|
|
#define TIMELOOP_CLOCK (TIMELOOP_S * CLOCKS_PER_SEC)
|
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)
|
|
|
|
|
|
|
|
#define MAX_MEM (2 GB - 64 MB)
|
|
|
|
#define DEFAULT_CHUNKSIZE (4 MB)
|
|
|
|
|
|
|
|
|
2016-06-29 11:43:11 +00:00
|
|
|
/*-************************************
|
2014-12-16 21:03:16 +00:00
|
|
|
* Local structures
|
|
|
|
***************************************/
|
2013-12-30 17:16:52 +00:00
|
|
|
struct chunkParameters
|
|
|
|
{
|
|
|
|
U32 id;
|
|
|
|
char* origBuffer;
|
|
|
|
char* compressedBuffer;
|
|
|
|
int origSize;
|
|
|
|
int compressedSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct compressionParameters
|
|
|
|
{
|
2015-04-21 17:31:35 +00:00
|
|
|
int (*compressionFunction)(const char* src, char* dst, int srcSize, int dstSize, int cLevel);
|
|
|
|
int (*decompressionFunction)(const char* src, char* dst, int dstSize);
|
2013-12-30 17:16:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-06-29 11:43:11 +00:00
|
|
|
/*-************************************
|
|
|
|
* Macro
|
2014-12-16 21:03:16 +00:00
|
|
|
***************************************/
|
2013-12-30 17:16:52 +00:00
|
|
|
#define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
|
|
|
|
|
|
|
|
|
2016-06-29 11:43:11 +00:00
|
|
|
/*-************************************
|
2014-12-16 21:03:16 +00:00
|
|
|
* Benchmark Parameters
|
|
|
|
***************************************/
|
2016-06-29 11:43:11 +00:00
|
|
|
static int g_chunkSize = DEFAULT_CHUNKSIZE;
|
2016-06-29 12:44:05 +00:00
|
|
|
static int g_nbIterations = NBLOOPS;
|
2013-12-30 17:16:52 +00:00
|
|
|
static int BMK_pause = 0;
|
|
|
|
|
2016-06-29 11:43:11 +00:00
|
|
|
void BMK_setBlocksize(int bsize) { g_chunkSize = bsize; }
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2015-03-10 15:57:42 +00:00
|
|
|
void BMK_setNbIterations(int nbLoops)
|
2013-12-30 17:16:52 +00:00
|
|
|
{
|
2016-06-29 12:44:05 +00:00
|
|
|
g_nbIterations = nbLoops;
|
|
|
|
DISPLAY("- %i iterations -\n", g_nbIterations);
|
2013-12-30 17:16:52 +00:00
|
|
|
}
|
|
|
|
|
2015-03-10 15:57:42 +00:00
|
|
|
void BMK_setPause(void) { BMK_pause = 1; }
|
2013-12-30 17:16:52 +00:00
|
|
|
|
|
|
|
|
2016-06-29 11:43:11 +00:00
|
|
|
/*-*******************************************************
|
2014-12-16 21:03:16 +00:00
|
|
|
* Private functions
|
|
|
|
**********************************************************/
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2016-06-29 12:35:19 +00:00
|
|
|
/** BMK_getClockSpan() :
|
|
|
|
works even if overflow; Typical max span ~ 30 mn */
|
|
|
|
static clock_t BMK_getClockSpan (clock_t clockStart)
|
2013-12-30 17:16:52 +00:00
|
|
|
{
|
2016-06-29 12:35:19 +00:00
|
|
|
return clock() - clockStart;
|
2013-12-30 17:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t BMK_findMaxMem(U64 requiredMem)
|
|
|
|
{
|
2016-06-29 12:44:05 +00:00
|
|
|
size_t const step = 64 MB;
|
|
|
|
void* testmem = NULL;
|
2013-12-30 17:16:52 +00:00
|
|
|
|
|
|
|
requiredMem = (((requiredMem >> 26) + 1) << 26);
|
|
|
|
requiredMem += 2*step;
|
|
|
|
if (requiredMem > MAX_MEM) requiredMem = MAX_MEM;
|
|
|
|
|
2016-06-29 11:43:11 +00:00
|
|
|
while (!testmem) {
|
2015-03-15 00:42:27 +00:00
|
|
|
if (requiredMem > step) requiredMem -= step;
|
|
|
|
else requiredMem >>= 1;
|
2016-06-29 12:44:05 +00:00
|
|
|
testmem = malloc ((size_t)requiredMem);
|
2013-12-30 17:16:52 +00:00
|
|
|
}
|
|
|
|
free (testmem);
|
2015-03-15 00:42:27 +00:00
|
|
|
|
|
|
|
/* keep some space available */
|
|
|
|
if (requiredMem > step) requiredMem -= step;
|
|
|
|
else requiredMem >>= 1;
|
|
|
|
|
|
|
|
return (size_t)requiredMem;
|
2013-12-30 17:16:52 +00:00
|
|
|
}
|
|
|
|
|
2015-03-07 12:23:00 +00:00
|
|
|
static U64 BMK_GetFileSize(const char* infilename)
|
2013-12-30 17:16:52 +00:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
struct _stat64 statbuf;
|
|
|
|
r = _stat64(infilename, &statbuf);
|
|
|
|
#else
|
|
|
|
struct stat statbuf;
|
|
|
|
r = stat(infilename, &statbuf);
|
|
|
|
#endif
|
2014-12-16 21:03:16 +00:00
|
|
|
if (r || !S_ISREG(statbuf.st_mode)) return 0; /* No good... */
|
2013-12-30 17:16:52 +00:00
|
|
|
return (U64)statbuf.st_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-29 11:43:11 +00:00
|
|
|
/*-*******************************************************
|
2014-12-16 21:03:16 +00:00
|
|
|
* Public function
|
|
|
|
**********************************************************/
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2016-09-02 20:59:18 +00:00
|
|
|
int BMK_benchLevel(const char** fileNamesTable, int nbFiles, int cLevel)
|
2013-12-30 17:16:52 +00:00
|
|
|
{
|
|
|
|
int fileIdx=0;
|
|
|
|
char* orig_buff;
|
|
|
|
struct compressionParameters compP;
|
|
|
|
int cfunctionId;
|
|
|
|
|
|
|
|
U64 totals = 0;
|
|
|
|
U64 totalz = 0;
|
|
|
|
double totalc = 0.;
|
|
|
|
double totald = 0.;
|
|
|
|
|
2014-12-17 11:20:17 +00:00
|
|
|
/* Init */
|
2016-09-02 20:59:18 +00:00
|
|
|
if (cLevel < LZ4HC_MIN_CLEVEL) cfunctionId = 0; else cfunctionId = 1;
|
2013-12-30 17:16:52 +00:00
|
|
|
switch (cfunctionId)
|
|
|
|
{
|
|
|
|
#ifdef COMPRESSOR0
|
|
|
|
case 0 : compP.compressionFunction = COMPRESSOR0; break;
|
|
|
|
#endif
|
|
|
|
#ifdef COMPRESSOR1
|
|
|
|
case 1 : compP.compressionFunction = COMPRESSOR1; break;
|
|
|
|
#endif
|
|
|
|
default : compP.compressionFunction = DEFAULTCOMPRESSOR;
|
|
|
|
}
|
|
|
|
|
2014-12-16 21:03:16 +00:00
|
|
|
/* Loop for each file */
|
2016-06-29 11:43:11 +00:00
|
|
|
while (fileIdx<nbFiles) {
|
2016-09-02 20:59:18 +00:00
|
|
|
const char* inFileName = fileNamesTable[fileIdx++];
|
2016-06-29 11:43:11 +00:00
|
|
|
FILE* const inFile = fopen( inFileName, "rb" );
|
|
|
|
U64 const inFileSize = BMK_GetFileSize(inFileName);
|
|
|
|
size_t benchedSize = BMK_findMaxMem(inFileSize * 2) / 2;
|
|
|
|
unsigned nbChunks;
|
2013-12-30 17:16:52 +00:00
|
|
|
int maxCompressedChunkSize;
|
|
|
|
size_t readSize;
|
2016-06-29 11:43:11 +00:00
|
|
|
char* compressedBuffer;
|
2013-12-30 17:16:52 +00:00
|
|
|
struct chunkParameters* chunkP;
|
|
|
|
U32 crcOrig;
|
|
|
|
|
2016-06-29 11:43:11 +00:00
|
|
|
/* Check file and memory conditions */
|
2015-04-12 07:21:35 +00:00
|
|
|
if (inFile==NULL) { DISPLAY( "Pb opening %s\n", inFileName); return 11; }
|
|
|
|
if (inFileSize==0) { DISPLAY( "file is empty\n"); fclose(inFile); return 11; }
|
2015-04-12 08:42:58 +00:00
|
|
|
if (benchedSize==0) { DISPLAY( "not enough memory\n"); fclose(inFile); return 11; }
|
2013-12-30 17:16:52 +00:00
|
|
|
if ((U64)benchedSize > inFileSize) benchedSize = (size_t)inFileSize;
|
2016-06-29 11:43:11 +00:00
|
|
|
if (benchedSize < inFileSize) {
|
|
|
|
DISPLAY("Not enough memory for '%s' full size; testing %u MB only...\n", inFileName, (unsigned)(benchedSize>>20));
|
2013-12-30 17:16:52 +00:00
|
|
|
}
|
|
|
|
|
2016-06-29 12:44:05 +00:00
|
|
|
/* Allocation */
|
2016-06-29 11:43:11 +00:00
|
|
|
nbChunks = (unsigned)(benchedSize / g_chunkSize) + 1;
|
|
|
|
chunkP = (struct chunkParameters*) malloc(nbChunks * sizeof(struct chunkParameters));
|
|
|
|
orig_buff = (char*)malloc(benchedSize);
|
|
|
|
maxCompressedChunkSize = LZ4_compressBound(g_chunkSize);
|
|
|
|
{ size_t const compressedBuffSize = (size_t)(nbChunks * maxCompressedChunkSize);
|
|
|
|
compressedBuffer = (char*)malloc(compressedBuffSize); }
|
|
|
|
|
|
|
|
if (!orig_buff || !compressedBuffer){
|
2013-12-30 17:16:52 +00:00
|
|
|
DISPLAY("\nError: not enough memory!\n");
|
|
|
|
free(orig_buff);
|
|
|
|
free(compressedBuffer);
|
|
|
|
free(chunkP);
|
|
|
|
fclose(inFile);
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
|
2014-12-16 21:03:16 +00:00
|
|
|
/* Init chunks data */
|
2016-06-29 11:43:11 +00:00
|
|
|
{ unsigned i;
|
2013-12-30 17:16:52 +00:00
|
|
|
size_t remaining = benchedSize;
|
|
|
|
char* in = orig_buff;
|
|
|
|
char* out = compressedBuffer;
|
2016-06-29 11:43:11 +00:00
|
|
|
for (i=0; i<nbChunks; i++) {
|
2013-12-30 17:16:52 +00:00
|
|
|
chunkP[i].id = i;
|
2016-06-29 11:43:11 +00:00
|
|
|
chunkP[i].origBuffer = in; in += g_chunkSize;
|
|
|
|
if (remaining > (size_t)g_chunkSize) { chunkP[i].origSize = g_chunkSize; remaining -= g_chunkSize; } else { chunkP[i].origSize = (int)remaining; remaining = 0; }
|
2013-12-30 17:16:52 +00:00
|
|
|
chunkP[i].compressedBuffer = out; out += maxCompressedChunkSize;
|
|
|
|
chunkP[i].compressedSize = 0;
|
2016-06-29 11:43:11 +00:00
|
|
|
} }
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2014-12-16 21:03:16 +00:00
|
|
|
/* Fill input buffer */
|
2013-12-30 17:16:52 +00:00
|
|
|
DISPLAY("Loading %s... \r", inFileName);
|
2016-09-02 20:59:18 +00:00
|
|
|
if (strlen(inFileName)>16) inFileName += strlen(inFileName)-16; /* can only display 16 characters */
|
2013-12-30 17:16:52 +00:00
|
|
|
readSize = fread(orig_buff, 1, benchedSize, inFile);
|
|
|
|
fclose(inFile);
|
|
|
|
|
2016-06-29 11:43:11 +00:00
|
|
|
if (readSize != benchedSize) {
|
|
|
|
DISPLAY("\nError: problem reading file '%s' !! \n", inFileName);
|
2013-12-30 17:16:52 +00:00
|
|
|
free(orig_buff);
|
|
|
|
free(compressedBuffer);
|
|
|
|
free(chunkP);
|
|
|
|
return 13;
|
|
|
|
}
|
|
|
|
|
2014-12-16 21:03:16 +00:00
|
|
|
/* Calculating input Checksum */
|
2016-06-29 11:43:11 +00:00
|
|
|
crcOrig = XXH32(orig_buff, benchedSize,0);
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2014-12-16 21:03:16 +00:00
|
|
|
/* Bench */
|
2016-06-29 11:43:11 +00:00
|
|
|
{ int loopNb;
|
|
|
|
size_t cSize = 0;
|
2013-12-30 17:16:52 +00:00
|
|
|
double fastestC = 100000000., fastestD = 100000000.;
|
2016-06-29 11:43:11 +00:00
|
|
|
double ratio = 0.;
|
|
|
|
U32 crcCheck = 0;
|
2013-12-30 17:16:52 +00:00
|
|
|
|
|
|
|
DISPLAY("\r%79s\r", "");
|
2016-06-29 12:44:05 +00:00
|
|
|
for (loopNb = 1; loopNb <= g_nbIterations; loopNb++) {
|
|
|
|
int nbLoops = 0;
|
2016-06-29 12:35:19 +00:00
|
|
|
clock_t clockStart, clockEnd;
|
2016-06-29 11:43:11 +00:00
|
|
|
unsigned chunkNb;
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2014-12-16 21:03:16 +00:00
|
|
|
/* Compression */
|
2016-09-02 20:59:18 +00:00
|
|
|
DISPLAY("%2i#%1i-%-14.14s : %9i ->\r", cLevel, loopNb, inFileName, (int)benchedSize);
|
2014-12-16 21:03:16 +00:00
|
|
|
{ size_t i; for (i=0; i<benchedSize; i++) compressedBuffer[i]=(char)i; } /* warmimg up memory */
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2016-06-29 12:35:19 +00:00
|
|
|
clockStart = clock();
|
|
|
|
while (clock() == clockStart);
|
|
|
|
clockStart = clock();
|
|
|
|
while (BMK_getClockSpan(clockStart) < TIMELOOP_CLOCK) {
|
|
|
|
for (chunkNb=0; chunkNb<nbChunks; chunkNb++)
|
2015-04-21 17:31:35 +00:00
|
|
|
chunkP[chunkNb].compressedSize = compP.compressionFunction(chunkP[chunkNb].origBuffer, chunkP[chunkNb].compressedBuffer, chunkP[chunkNb].origSize, maxCompressedChunkSize, cLevel);
|
2016-06-29 12:35:19 +00:00
|
|
|
nbLoops++;
|
2013-12-30 17:16:52 +00:00
|
|
|
}
|
2016-06-29 12:35:19 +00:00
|
|
|
clockEnd = BMK_getClockSpan(clockStart);
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2015-04-12 08:42:58 +00:00
|
|
|
nbLoops += !nbLoops; /* avoid division by zero */
|
2016-06-29 12:35:19 +00:00
|
|
|
if ((double)clockEnd < fastestC*nbLoops) fastestC = (double)clockEnd/nbLoops;
|
2013-12-30 17:16:52 +00:00
|
|
|
cSize=0; for (chunkNb=0; chunkNb<nbChunks; chunkNb++) cSize += chunkP[chunkNb].compressedSize;
|
|
|
|
ratio = (double)cSize/(double)benchedSize*100.;
|
|
|
|
|
2016-09-02 20:59:18 +00:00
|
|
|
DISPLAY("%2i#%1i-%-14.14s : %9i -> %9i (%5.2f%%),%7.1f MB/s\r",
|
|
|
|
cLevel, loopNb, inFileName, (int)benchedSize, (int)cSize, ratio, (double)benchedSize / (fastestC / CLOCKS_PER_SEC) / 1000000);
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2014-12-16 21:03:16 +00:00
|
|
|
/* Decompression */
|
|
|
|
{ size_t i; for (i=0; i<benchedSize; i++) orig_buff[i]=0; } /* zeroing area, for CRC checking */
|
2013-12-30 17:16:52 +00:00
|
|
|
|
|
|
|
nbLoops = 0;
|
2016-06-29 12:35:19 +00:00
|
|
|
clockStart = clock();
|
|
|
|
while (clock() == clockStart);
|
|
|
|
clockStart = clock();
|
|
|
|
while (BMK_getClockSpan(clockStart) < TIMELOOP_CLOCK) {
|
|
|
|
for (chunkNb=0; chunkNb<nbChunks; chunkNb++)
|
2016-06-29 15:48:28 +00:00
|
|
|
//chunkP[chunkNb].compressedSize = LZ4_decompress_fast(chunkP[chunkNb].compressedBuffer, chunkP[chunkNb].origBuffer, chunkP[chunkNb].origSize);
|
|
|
|
LZ4_decompress_safe(chunkP[chunkNb].compressedBuffer, chunkP[chunkNb].origBuffer, chunkP[chunkNb].compressedSize, chunkP[chunkNb].origSize);
|
2016-06-29 12:35:19 +00:00
|
|
|
nbLoops++;
|
2013-12-30 17:16:52 +00:00
|
|
|
}
|
2016-06-29 12:35:19 +00:00
|
|
|
clockEnd = BMK_getClockSpan(clockStart);
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2015-04-12 07:21:35 +00:00
|
|
|
nbLoops += !nbLoops; /* avoid division by zero */
|
2016-06-29 12:35:19 +00:00
|
|
|
if ((double)clockEnd < fastestD*nbLoops) fastestD = (double)clockEnd/nbLoops;
|
2016-09-02 20:59:18 +00:00
|
|
|
DISPLAY("%2i#%1i-%-14.14s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s \r",
|
|
|
|
cLevel, loopNb, inFileName, (int)benchedSize, (int)cSize, ratio,
|
2016-06-29 12:35:19 +00:00
|
|
|
(double)benchedSize / (fastestC / CLOCKS_PER_SEC) / 1000000, (double)benchedSize / (fastestD / CLOCKS_PER_SEC) / 1000000 );
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2014-12-16 21:03:16 +00:00
|
|
|
/* CRC Checking */
|
2016-06-29 11:43:11 +00:00
|
|
|
crcCheck = XXH32(orig_buff, benchedSize,0);
|
2013-12-30 17:16:52 +00:00
|
|
|
if (crcOrig!=crcCheck) { DISPLAY("\n!!! WARNING !!! %14s : Invalid Checksum : %x != %x\n", inFileName, (unsigned)crcOrig, (unsigned)crcCheck); break; }
|
|
|
|
}
|
|
|
|
|
2016-06-29 11:43:11 +00:00
|
|
|
if (crcOrig==crcCheck) {
|
2016-06-29 12:44:05 +00:00
|
|
|
if (ratio < 100.)
|
2016-09-02 20:59:18 +00:00
|
|
|
DISPLAY("%2i#%-16.16s : %9i -> %9i (%5.2f%%),%7.1f MB/s ,%7.1f MB/s \n",
|
|
|
|
cLevel, inFileName, (int)benchedSize, (int)cSize, ratio,
|
2016-06-29 12:35:19 +00:00
|
|
|
(double)benchedSize / (fastestC / CLOCKS_PER_SEC) / 1000000, (double)benchedSize / (fastestD / CLOCKS_PER_SEC) / 1000000 );
|
2013-12-30 17:16:52 +00:00
|
|
|
else
|
2016-09-02 20:59:18 +00:00
|
|
|
DISPLAY("%2i#%-16.16s : %9i -> %9i (%5.1f%%),%7.1f MB/s ,%7.1f MB/s \n",
|
|
|
|
cLevel, inFileName, (int)benchedSize, (int)cSize, ratio,
|
2016-06-29 12:35:19 +00:00
|
|
|
(double)benchedSize / (fastestC / CLOCKS_PER_SEC) / 1000000, (double)benchedSize / (fastestD / CLOCKS_PER_SEC) / 1000000 );
|
2013-12-30 17:16:52 +00:00
|
|
|
}
|
|
|
|
totals += benchedSize;
|
|
|
|
totalz += cSize;
|
|
|
|
totalc += fastestC;
|
|
|
|
totald += fastestD;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(orig_buff);
|
|
|
|
free(compressedBuffer);
|
|
|
|
free(chunkP);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nbFiles > 1)
|
2016-09-02 20:59:18 +00:00
|
|
|
DISPLAY("%2i#%-16.16s :%10llu ->%10llu (%5.2f%%), %6.1f MB/s , %6.1f MB/s\n", cLevel, " TOTAL",
|
2016-06-29 12:56:50 +00:00
|
|
|
(long long unsigned)totals, (long long unsigned int)totalz, (double)totalz/(double)totals*100.,
|
|
|
|
(double)totals/(totalc/CLOCKS_PER_SEC)/1000000, (double)totals/(totald/CLOCKS_PER_SEC)/1000000);
|
2013-12-30 17:16:52 +00:00
|
|
|
|
2015-04-12 07:21:35 +00:00
|
|
|
if (BMK_pause) { DISPLAY("\npress enter...\n"); (void)getchar(); }
|
2013-12-30 17:16:52 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2016-09-02 20:59:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel, int cLevelLast)
|
|
|
|
{
|
|
|
|
int i, res = 0;
|
|
|
|
|
|
|
|
if (cLevel > LZ4HC_MAX_CLEVEL) cLevel = LZ4HC_MAX_CLEVEL;
|
|
|
|
if (cLevelLast > LZ4HC_MAX_CLEVEL) cLevelLast = LZ4HC_MAX_CLEVEL;
|
|
|
|
if (cLevelLast < cLevel) cLevelLast = cLevel;
|
|
|
|
|
|
|
|
DISPLAY("Benchmarking levels from %d to %d\n", cLevel, cLevelLast);
|
|
|
|
for (i=cLevel; i<=cLevelLast; i++) {
|
|
|
|
res = BMK_benchLevel(fileNamesTable, nbFiles, i);
|
|
|
|
if (res != 0) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|