fullbench: tests for ZBUFF_createCCtx_advanced and ZBUFF_createDCtx_advanced
This commit is contained in:
+5
-2
@@ -42,8 +42,11 @@ extern "C" {
|
|||||||
/*-****************************************
|
/*-****************************************
|
||||||
* Dependencies
|
* Dependencies
|
||||||
******************************************/
|
******************************************/
|
||||||
#include <stddef.h> /* size_t, ptrdiff_t */
|
#include <stddef.h> /* size_t, ptrdiff_t */
|
||||||
#include <string.h> /* memcpy */
|
#include <string.h> /* memcpy */
|
||||||
|
#if defined(_MSC_VER) /* Visual Studio */
|
||||||
|
# include <stdlib.h> /* _byteswap_ulong */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*-****************************************
|
/*-****************************************
|
||||||
|
|||||||
@@ -55,8 +55,11 @@ struct ZSTD_stats_s {
|
|||||||
|
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Advanced functions
|
* Stats functions
|
||||||
***************************************/
|
***************************************/
|
||||||
|
MEM_STATIC ZSTD_stats_t* ZSTD_statsAlloc() { return malloc(sizeof(ZSTD_stats_t)); }
|
||||||
|
MEM_STATIC void ZSTD_statsFree(struct ZSTD_stats_s* stats) { free(stats); }
|
||||||
|
|
||||||
MEM_STATIC void ZSTD_statsPrint(ZSTD_stats_t* stats, U32 searchLength)
|
MEM_STATIC void ZSTD_statsPrint(ZSTD_stats_t* stats, U32 searchLength)
|
||||||
{
|
{
|
||||||
stats->totalMatchSum += stats->totalSeqSum * ((searchLength == 3) ? 3 : 4);
|
stats->totalMatchSum += stats->totalSeqSum * ((searchLength == 3) ? 3 : 4);
|
||||||
@@ -155,6 +158,8 @@ MEM_STATIC void ZSTD_statsUpdatePrices(ZSTD_stats_t* stats, size_t litLength, co
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
struct ZSTD_stats_s { U32 unused; };
|
struct ZSTD_stats_s { U32 unused; };
|
||||||
|
MEM_STATIC ZSTD_stats_t* ZSTD_statsAlloc(void) { return NULL; }
|
||||||
|
MEM_STATIC void ZSTD_statsFree(struct ZSTD_stats_s* stats) { (void)stats; }
|
||||||
MEM_STATIC void ZSTD_statsPrint(ZSTD_stats_t* stats, U32 searchLength) { (void)stats; (void)searchLength; }
|
MEM_STATIC void ZSTD_statsPrint(ZSTD_stats_t* stats, U32 searchLength) { (void)stats; (void)searchLength; }
|
||||||
MEM_STATIC void ZSTD_statsInit(ZSTD_stats_t* stats) { (void)stats; }
|
MEM_STATIC void ZSTD_statsInit(ZSTD_stats_t* stats) { (void)stats; }
|
||||||
MEM_STATIC void ZSTD_statsResetFreqs(ZSTD_stats_t* stats) { (void)stats; }
|
MEM_STATIC void ZSTD_statsResetFreqs(ZSTD_stats_t* stats) { (void)stats; }
|
||||||
|
|||||||
@@ -2052,8 +2052,7 @@ static size_t ZSTD_compress_generic (ZSTD_CCtx* zc,
|
|||||||
BYTE* const ostart = (BYTE*)dst;
|
BYTE* const ostart = (BYTE*)dst;
|
||||||
BYTE* op = ostart;
|
BYTE* op = ostart;
|
||||||
const U32 maxDist = 1 << zc->params.cParams.windowLog;
|
const U32 maxDist = 1 << zc->params.cParams.windowLog;
|
||||||
ZSTD_stats_t* stats = (ZSTD_stats_t*) zc->customAlloc(sizeof(ZSTD_stats_t));
|
ZSTD_stats_t* stats = ZSTD_statsAlloc();
|
||||||
if (!stats) return ERROR(memory_allocation);
|
|
||||||
zc->seqStore.stats = stats;
|
zc->seqStore.stats = stats;
|
||||||
ZSTD_statsInit(stats);
|
ZSTD_statsInit(stats);
|
||||||
|
|
||||||
@@ -2061,7 +2060,7 @@ static size_t ZSTD_compress_generic (ZSTD_CCtx* zc,
|
|||||||
size_t cSize;
|
size_t cSize;
|
||||||
ZSTD_statsResetFreqs(stats);
|
ZSTD_statsResetFreqs(stats);
|
||||||
|
|
||||||
if (dstCapacity < ZSTD_blockHeaderSize + MIN_CBLOCK_SIZE) { zc->customFree(stats); return ERROR(dstSize_tooSmall); } /* not enough space to store compressed block */
|
if (dstCapacity < ZSTD_blockHeaderSize + MIN_CBLOCK_SIZE) { ZSTD_statsFree(stats); return ERROR(dstSize_tooSmall); } /* not enough space to store compressed block */
|
||||||
if (remaining < blockSize) blockSize = remaining;
|
if (remaining < blockSize) blockSize = remaining;
|
||||||
|
|
||||||
if ((U32)(ip+blockSize - zc->base) > zc->loadedDictEnd + maxDist) {
|
if ((U32)(ip+blockSize - zc->base) > zc->loadedDictEnd + maxDist) {
|
||||||
@@ -2072,11 +2071,11 @@ static size_t ZSTD_compress_generic (ZSTD_CCtx* zc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cSize = ZSTD_compressBlock_internal(zc, op+ZSTD_blockHeaderSize, dstCapacity-ZSTD_blockHeaderSize, ip, blockSize);
|
cSize = ZSTD_compressBlock_internal(zc, op+ZSTD_blockHeaderSize, dstCapacity-ZSTD_blockHeaderSize, ip, blockSize);
|
||||||
if (ZSTD_isError(cSize)) { zc->customFree(stats); return cSize; }
|
if (ZSTD_isError(cSize)) { ZSTD_statsFree(stats); return cSize; }
|
||||||
|
|
||||||
if (cSize == 0) { /* block is not compressible */
|
if (cSize == 0) { /* block is not compressible */
|
||||||
cSize = ZSTD_noCompressBlock(op, dstCapacity, ip, blockSize);
|
cSize = ZSTD_noCompressBlock(op, dstCapacity, ip, blockSize);
|
||||||
if (ZSTD_isError(cSize)) { zc->customFree(stats); return cSize; }
|
if (ZSTD_isError(cSize)) { ZSTD_statsFree(stats); return cSize; }
|
||||||
} else {
|
} else {
|
||||||
op[0] = (BYTE)(cSize>>16);
|
op[0] = (BYTE)(cSize>>16);
|
||||||
op[1] = (BYTE)(cSize>>8);
|
op[1] = (BYTE)(cSize>>8);
|
||||||
@@ -2092,7 +2091,7 @@ static size_t ZSTD_compress_generic (ZSTD_CCtx* zc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ZSTD_statsPrint(stats, zc->params.cParams.searchLength);
|
ZSTD_statsPrint(stats, zc->params.cParams.searchLength);
|
||||||
zc->customFree(stats);
|
ZSTD_statsFree(stats);
|
||||||
return op-ostart;
|
return op-ostart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+50
-1
@@ -213,6 +213,19 @@ size_t local_ZSTD_decompressContinue(void* dst, size_t dstCapacity, void* buff2,
|
|||||||
/*_*******************************************************
|
/*_*******************************************************
|
||||||
* Bench functions
|
* Bench functions
|
||||||
*********************************************************/
|
*********************************************************/
|
||||||
|
void* BMK_allocFunction(size_t size)
|
||||||
|
{
|
||||||
|
void* address = malloc(size);
|
||||||
|
/* printf("alloc %p, %d \n", address, (int)size); */
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BMK_freeFunction(void* address)
|
||||||
|
{
|
||||||
|
/* printf("free %p \n", address); */
|
||||||
|
free(address);
|
||||||
|
}
|
||||||
|
|
||||||
static size_t benchMem(const void* src, size_t srcSize, U32 benchNb)
|
static size_t benchMem(const void* src, size_t srcSize, U32 benchNb)
|
||||||
{
|
{
|
||||||
BYTE* dstBuff;
|
BYTE* dstBuff;
|
||||||
@@ -220,6 +233,7 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb)
|
|||||||
BYTE* buff2;
|
BYTE* buff2;
|
||||||
const char* benchName;
|
const char* benchName;
|
||||||
size_t (*benchFunction)(void* dst, size_t dstSize, void* verifBuff, const void* src, size_t srcSize);
|
size_t (*benchFunction)(void* dst, size_t dstSize, void* verifBuff, const void* src, size_t srcSize);
|
||||||
|
ZSTD_customMem customMem = { BMK_allocFunction, BMK_freeFunction };
|
||||||
double bestTime = 100000000.;
|
double bestTime = 100000000.;
|
||||||
|
|
||||||
/* Selection */
|
/* Selection */
|
||||||
@@ -247,8 +261,14 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb)
|
|||||||
benchFunction = local_ZBUFF_compress; benchName = "ZBUFF_compressContinue";
|
benchFunction = local_ZBUFF_compress; benchName = "ZBUFF_compressContinue";
|
||||||
break;
|
break;
|
||||||
case 42:
|
case 42:
|
||||||
|
benchFunction = local_ZBUFF_compress; benchName = "ZBUFF_createCCtx_advanced/ZBUFF_compressContinue";
|
||||||
|
break;
|
||||||
|
case 43:
|
||||||
benchFunction = local_ZBUFF_decompress; benchName = "ZBUFF_decompressContinue";
|
benchFunction = local_ZBUFF_decompress; benchName = "ZBUFF_decompressContinue";
|
||||||
break;
|
break;
|
||||||
|
case 44:
|
||||||
|
benchFunction = local_ZBUFF_decompress; benchName = "ZBUFF_createDCtx_advanced/ZBUFF_decompressContinue";
|
||||||
|
break;
|
||||||
default :
|
default :
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -323,9 +343,16 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb)
|
|||||||
if (g_zbcc==NULL) g_zbcc = ZBUFF_createCCtx();
|
if (g_zbcc==NULL) g_zbcc = ZBUFF_createCCtx();
|
||||||
break;
|
break;
|
||||||
case 42 :
|
case 42 :
|
||||||
|
if (g_zbcc==NULL) g_zbcc = ZBUFF_createCCtx_advanced(customMem);
|
||||||
|
break;
|
||||||
|
case 43 :
|
||||||
if (g_zbdc==NULL) g_zbdc = ZBUFF_createDCtx();
|
if (g_zbdc==NULL) g_zbdc = ZBUFF_createDCtx();
|
||||||
g_cSize = ZSTD_compress(buff2, dstBuffSize, src, srcSize, 1);
|
g_cSize = ZSTD_compress(buff2, dstBuffSize, src, srcSize, 1);
|
||||||
break;
|
break;
|
||||||
|
case 44 :
|
||||||
|
if (g_zbdc==NULL) g_zbdc = ZBUFF_createDCtx_advanced(customMem);
|
||||||
|
g_cSize = ZSTD_compress(buff2, dstBuffSize, src, srcSize, 1);
|
||||||
|
break;
|
||||||
|
|
||||||
/* test functions */
|
/* test functions */
|
||||||
/* by convention, test functions can be added > 100 */
|
/* by convention, test functions can be added > 100 */
|
||||||
@@ -355,7 +382,29 @@ static size_t benchMem(const void* src, size_t srcSize, U32 benchNb)
|
|||||||
averageTime = (((double)BMK_clockSpan(clockStart)) / CLOCKS_PER_SEC) / nbRounds;
|
averageTime = (((double)BMK_clockSpan(clockStart)) / CLOCKS_PER_SEC) / nbRounds;
|
||||||
if (averageTime < bestTime) bestTime = averageTime;
|
if (averageTime < bestTime) bestTime = averageTime;
|
||||||
DISPLAY("%2i- %-30.30s : %7.1f MB/s (%9u)\r", loopNb, benchName, (double)srcSize / (1 MB) / bestTime, (U32)benchResult);
|
DISPLAY("%2i- %-30.30s : %7.1f MB/s (%9u)\r", loopNb, benchName, (double)srcSize / (1 MB) / bestTime, (U32)benchResult);
|
||||||
}}
|
}
|
||||||
|
|
||||||
|
/* free allocated structures */
|
||||||
|
switch(benchNb)
|
||||||
|
{
|
||||||
|
case 11 :
|
||||||
|
if (g_zcc) { ZSTD_freeCCtx(g_zcc); g_zcc=NULL; }
|
||||||
|
break;
|
||||||
|
case 12 :
|
||||||
|
case 31:
|
||||||
|
case 32:
|
||||||
|
if (g_zdc) { ZSTD_freeDCtx(g_zdc); g_zdc=NULL; }
|
||||||
|
break;
|
||||||
|
case 41 :
|
||||||
|
case 42 :
|
||||||
|
if (g_zbcc) { ZBUFF_freeCCtx(g_zbcc); g_zbcc=NULL; }
|
||||||
|
break;
|
||||||
|
case 43 :
|
||||||
|
case 44 :
|
||||||
|
if (g_zbdc) { ZBUFF_freeDCtx(g_zbdc); g_zbdc=NULL; }
|
||||||
|
break;
|
||||||
|
default : ;
|
||||||
|
} }
|
||||||
DISPLAY("%2u\n", benchNb);
|
DISPLAY("%2u\n", benchNb);
|
||||||
|
|
||||||
_cleanOut:
|
_cleanOut:
|
||||||
|
|||||||
Reference in New Issue
Block a user