mirror of
https://github.com/facebook/zstd.git
synced 2025-12-02 00:02:47 -05:00
minor variable renaming
This commit is contained in:
parent
c540976a4b
commit
8b7e1b795d
@ -519,10 +519,8 @@ static PrepResult prepCopy(void* dst, size_t dstCapacity, const void* src, size_
|
|||||||
|
|
||||||
static PrepResult prepShorterDstCapacity(void* dst, size_t dstCapacity, const void* src, size_t srcSize, int cLevel)
|
static PrepResult prepShorterDstCapacity(void* dst, size_t dstCapacity, const void* src, size_t srcSize, int cLevel)
|
||||||
{
|
{
|
||||||
const PrepResult r = { srcSize, srcSize, dstCapacity-1};
|
PrepResult r = prepCopy(dst, dstCapacity, src, srcSize, cLevel);
|
||||||
(void)cLevel;
|
r.moddedDstCapacity = dstCapacity - 1;
|
||||||
assert(dstCapacity >= srcSize);
|
|
||||||
memcpy(dst, src, srcSize);
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -564,33 +562,33 @@ static BenchScenario kScenarios[] = {
|
|||||||
/*_*******************************************************
|
/*_*******************************************************
|
||||||
* Bench functions
|
* Bench functions
|
||||||
*********************************************************/
|
*********************************************************/
|
||||||
static int benchMem(unsigned benchNb,
|
static int benchMem(unsigned scenarioID,
|
||||||
const void* origSrc, size_t origSrcSize,
|
const void* origSrc, size_t origSrcSize,
|
||||||
int cLevel, ZSTD_compressionParameters cparams)
|
int cLevel, ZSTD_compressionParameters cparams)
|
||||||
{
|
{
|
||||||
size_t dstBuffCapacity = ZSTD_compressBound(origSrcSize);
|
size_t dstCapacity = ZSTD_compressBound(origSrcSize);
|
||||||
void* dstBuff;
|
void* dst;
|
||||||
void* prepBuff;
|
void* prepBuff;
|
||||||
size_t prepBuffCapacity=dstBuffCapacity, prepBuffSize;
|
size_t prepBuffCapacity=dstCapacity, prepBuffSize;
|
||||||
void* payload;
|
void* payload;
|
||||||
const char* benchName;
|
const char* benchName;
|
||||||
BMK_benchFn_t benchFunction;
|
BMK_benchFn_t benchFunction;
|
||||||
PrepFunction_f prep_f;
|
PrepFunction_f prep_f;
|
||||||
int errorcode = 0;
|
int errorcode = 0;
|
||||||
|
|
||||||
if (benchNb >= NB_SCENARIOS) return 0; /* scenario doesn't exist */
|
if (scenarioID >= NB_SCENARIOS) return 0; /* scenario doesn't exist */
|
||||||
|
|
||||||
benchName = kScenarios[benchNb].name;
|
benchName = kScenarios[scenarioID].name;
|
||||||
benchFunction = kScenarios[benchNb].benchedFunction;
|
benchFunction = kScenarios[scenarioID].benchedFunction;
|
||||||
prep_f = kScenarios[benchNb].preparation_f;
|
prep_f = kScenarios[scenarioID].preparation_f;
|
||||||
if (prep_f == NULL) prep_f = prepCopy; /* default */
|
if (prep_f == NULL) prep_f = prepCopy; /* default */
|
||||||
|
|
||||||
/* Allocation */
|
/* Allocation */
|
||||||
dstBuff = malloc(dstBuffCapacity);
|
dst = malloc(dstCapacity);
|
||||||
prepBuff = malloc(prepBuffCapacity);
|
prepBuff = malloc(prepBuffCapacity);
|
||||||
if ((!dstBuff) || (!prepBuff)) {
|
if ((!dst) || (!prepBuff)) {
|
||||||
DISPLAY("\nError: not enough memory!\n");
|
DISPLAY("\nError: not enough memory!\n");
|
||||||
free(dstBuff); free(prepBuff);
|
free(dst); free(prepBuff);
|
||||||
return 12;
|
return 12;
|
||||||
}
|
}
|
||||||
if (g_zcc==NULL) g_zcc = ZSTD_createCCtx();
|
if (g_zcc==NULL) g_zcc = ZSTD_createCCtx();
|
||||||
@ -625,16 +623,16 @@ static int benchMem(unsigned benchNb,
|
|||||||
{ PrepResult pr = prep_f(prepBuff, prepBuffCapacity, origSrc, origSrcSize, cLevel);
|
{ PrepResult pr = prep_f(prepBuff, prepBuffCapacity, origSrc, origSrcSize, cLevel);
|
||||||
prepBuffSize = pr.prepSize;
|
prepBuffSize = pr.prepSize;
|
||||||
origSrcSize = pr.fixedOrigSize;
|
origSrcSize = pr.fixedOrigSize;
|
||||||
if (pr.moddedDstCapacity) dstBuffCapacity = pr.moddedDstCapacity;
|
if (pr.moddedDstCapacity) dstCapacity = pr.moddedDstCapacity;
|
||||||
}
|
}
|
||||||
if (prepBuffSize==0) goto _cleanOut; /* failed preparation */
|
if (prepBuffSize==0) goto _cleanOut; /* failed preparation */
|
||||||
|
|
||||||
/* warming up dstBuff */
|
/* warming up dstBuff */
|
||||||
{ size_t i; for (i=0; i<dstBuffCapacity; i++) ((BYTE*)dstBuff)[i]=(BYTE)i; }
|
{ size_t i; for (i=0; i<dstCapacity; i++) ((BYTE*)dst)[i]=(BYTE)i; }
|
||||||
|
|
||||||
/* benchmark loop */
|
/* benchmark loop */
|
||||||
{ BMK_timedFnState_t* const tfs = BMK_createTimedFnState(g_nbIterations * 1000, 1000);
|
{ BMK_timedFnState_t* const tfs = BMK_createTimedFnState(g_nbIterations * 1000, 1000);
|
||||||
void* const avoidStrictAliasingPtr = &dstBuff;
|
void* const avoidStrictAliasingPtr = &dst;
|
||||||
const void* prepSrc = prepBuff;
|
const void* prepSrc = prepBuff;
|
||||||
BMK_benchParams_t bp;
|
BMK_benchParams_t bp;
|
||||||
BMK_runTime_t bestResult;
|
BMK_runTime_t bestResult;
|
||||||
@ -652,7 +650,7 @@ static int benchMem(unsigned benchNb,
|
|||||||
bp.srcSizes = &prepBuffSize;
|
bp.srcSizes = &prepBuffSize;
|
||||||
bp.dstBuffers = (void* const*) avoidStrictAliasingPtr; /* circumvent strict aliasing warning on gcc-8,
|
bp.dstBuffers = (void* const*) avoidStrictAliasingPtr; /* circumvent strict aliasing warning on gcc-8,
|
||||||
* because gcc considers that `void* const *` and `void**` are 2 different types */
|
* because gcc considers that `void* const *` and `void**` are 2 different types */
|
||||||
bp.dstCapacities = &dstBuffCapacity;
|
bp.dstCapacities = &dstCapacity;
|
||||||
bp.blockResults = NULL;
|
bp.blockResults = NULL;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -668,7 +666,7 @@ static int benchMem(unsigned benchNb,
|
|||||||
if (newResult.nanoSecPerRun < bestResult.nanoSecPerRun )
|
if (newResult.nanoSecPerRun < bestResult.nanoSecPerRun )
|
||||||
bestResult.nanoSecPerRun = newResult.nanoSecPerRun;
|
bestResult.nanoSecPerRun = newResult.nanoSecPerRun;
|
||||||
DISPLAY("\r%2u#%-31.31s:%8.1f MB/s (%8u) ",
|
DISPLAY("\r%2u#%-31.31s:%8.1f MB/s (%8u) ",
|
||||||
benchNb, benchName,
|
scenarioID, benchName,
|
||||||
(double)origSrcSize * TIMELOOP_NANOSEC / bestResult.nanoSecPerRun / MB_UNIT,
|
(double)origSrcSize * TIMELOOP_NANOSEC / bestResult.nanoSecPerRun / MB_UNIT,
|
||||||
(unsigned)newResult.sumOfReturn );
|
(unsigned)newResult.sumOfReturn );
|
||||||
}
|
}
|
||||||
@ -681,7 +679,7 @@ static int benchMem(unsigned benchNb,
|
|||||||
|
|
||||||
_cleanOut:
|
_cleanOut:
|
||||||
free(prepBuff);
|
free(prepBuff);
|
||||||
free(dstBuff);
|
free(dst);
|
||||||
ZSTD_freeCCtx(g_zcc); g_zcc=NULL;
|
ZSTD_freeCCtx(g_zcc); g_zcc=NULL;
|
||||||
ZSTD_freeDCtx(g_zdc); g_zdc=NULL;
|
ZSTD_freeDCtx(g_zdc); g_zdc=NULL;
|
||||||
ZSTD_freeCStream(g_cstream); g_cstream=NULL;
|
ZSTD_freeCStream(g_cstream); g_cstream=NULL;
|
||||||
@ -690,7 +688,8 @@ _cleanOut:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int benchSample(U32 benchNb,
|
#define BENCH_ALL_SCENARIOS 999
|
||||||
|
static int benchSample(U32 scenarioID,
|
||||||
size_t benchedSize, double compressibility,
|
size_t benchedSize, double compressibility,
|
||||||
int cLevel, ZSTD_compressionParameters cparams)
|
int cLevel, ZSTD_compressionParameters cparams)
|
||||||
{
|
{
|
||||||
@ -704,19 +703,20 @@ static int benchSample(U32 benchNb,
|
|||||||
/* bench */
|
/* bench */
|
||||||
DISPLAY("\r%70s\r", "");
|
DISPLAY("\r%70s\r", "");
|
||||||
DISPLAY(" Sample %u bytes : \n", (unsigned)benchedSize);
|
DISPLAY(" Sample %u bytes : \n", (unsigned)benchedSize);
|
||||||
if (benchNb) {
|
if (scenarioID == BENCH_ALL_SCENARIOS) {
|
||||||
benchMem(benchNb, origBuff, benchedSize, cLevel, cparams);
|
for (scenarioID=0; scenarioID<100; scenarioID++) {
|
||||||
} else { /* 0 == run all tests */
|
benchMem(scenarioID, origBuff, benchedSize, cLevel, cparams);
|
||||||
for (benchNb=0; benchNb<100; benchNb++) {
|
}
|
||||||
benchMem(benchNb, origBuff, benchedSize, cLevel, cparams);
|
} else {
|
||||||
} }
|
benchMem(scenarioID, origBuff, benchedSize, cLevel, cparams);
|
||||||
|
}
|
||||||
|
|
||||||
free(origBuff);
|
free(origBuff);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int benchFiles(U32 benchNb,
|
static int benchFiles(U32 scenarioID,
|
||||||
const char** fileNamesTable, const int nbFiles,
|
const char** fileNamesTable, const int nbFiles,
|
||||||
int cLevel, ZSTD_compressionParameters cparams)
|
int cLevel, ZSTD_compressionParameters cparams)
|
||||||
{
|
{
|
||||||
@ -762,13 +762,12 @@ static int benchFiles(U32 benchNb,
|
|||||||
/* bench */
|
/* bench */
|
||||||
DISPLAY("\r%70s\r", ""); /* blank line */
|
DISPLAY("\r%70s\r", ""); /* blank line */
|
||||||
DISPLAY(" %s : \n", inFileName);
|
DISPLAY(" %s : \n", inFileName);
|
||||||
if (benchNb) {
|
if (scenarioID == BENCH_ALL_SCENARIOS) {
|
||||||
benchMem(benchNb, origBuff, benchedSize, cLevel, cparams);
|
for (scenarioID=0; scenarioID<100; scenarioID++) {
|
||||||
} else {
|
benchMem(scenarioID, origBuff, benchedSize, cLevel, cparams);
|
||||||
for (benchNb=0; benchNb<100; benchNb++) {
|
|
||||||
benchMem(benchNb, origBuff, benchedSize, cLevel, cparams);
|
|
||||||
}
|
}
|
||||||
benchNb = 0;
|
} else {
|
||||||
|
benchMem(scenarioID, origBuff, benchedSize, cLevel, cparams);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(origBuff);
|
free(origBuff);
|
||||||
@ -858,7 +857,7 @@ int main(int argc, const char** argv)
|
|||||||
int argNb, filenamesStart=0, result;
|
int argNb, filenamesStart=0, result;
|
||||||
const char* const exename = argv[0];
|
const char* const exename = argv[0];
|
||||||
const char* input_filename = NULL;
|
const char* input_filename = NULL;
|
||||||
U32 benchNb = 0, main_pause = 0;
|
U32 scenarioID = BENCH_ALL_SCENARIOS, main_pause = 0;
|
||||||
int cLevel = DEFAULT_CLEVEL;
|
int cLevel = DEFAULT_CLEVEL;
|
||||||
ZSTD_compressionParameters cparams = ZSTD_getCParams(cLevel, 0, 0);
|
ZSTD_compressionParameters cparams = ZSTD_getCParams(cLevel, 0, 0);
|
||||||
size_t sampleSize = kSampleSizeDefault;
|
size_t sampleSize = kSampleSizeDefault;
|
||||||
@ -909,7 +908,7 @@ int main(int argc, const char** argv)
|
|||||||
/* Select specific algorithm to bench */
|
/* Select specific algorithm to bench */
|
||||||
case 'b':
|
case 'b':
|
||||||
argument++;
|
argument++;
|
||||||
benchNb = readU32FromChar(&argument);
|
scenarioID = readU32FromChar(&argument);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Select compression level to use */
|
/* Select compression level to use */
|
||||||
@ -951,9 +950,9 @@ int main(int argc, const char** argv)
|
|||||||
|
|
||||||
|
|
||||||
if (filenamesStart==0) /* no input file */
|
if (filenamesStart==0) /* no input file */
|
||||||
result = benchSample(benchNb, sampleSize, compressibility, cLevel, cparams);
|
result = benchSample(scenarioID, sampleSize, compressibility, cLevel, cparams);
|
||||||
else
|
else
|
||||||
result = benchFiles(benchNb, argv+filenamesStart, argc-filenamesStart, cLevel, cparams);
|
result = benchFiles(scenarioID, argv+filenamesStart, argc-filenamesStart, cLevel, cparams);
|
||||||
|
|
||||||
if (main_pause) { int unused; printf("press enter...\n"); unused = getchar(); (void)unused; }
|
if (main_pause) { int unused; printf("press enter...\n"); unused = getchar(); (void)unused; }
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user