minor variable isolation
and remove a goto
This commit is contained in:
parent
b58c685cf7
commit
a5b66e34c7
130
programs/bench.c
130
programs/bench.c
@ -239,17 +239,15 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
|||||||
RDG_genBuffer(compressedBuffer, maxCompressedSize, 0.10, 0.50, 1);
|
RDG_genBuffer(compressedBuffer, maxCompressedSize, 0.10, 0.50, 1);
|
||||||
|
|
||||||
/* Bench */
|
/* Bench */
|
||||||
{ size_t cSize = 0;
|
{ double fastestC = 100000000., fastestD = 100000000.;
|
||||||
double fastestC = 100000000., fastestD = 100000000.;
|
|
||||||
double ratio = 0.;
|
|
||||||
U64 crcCheck = 0;
|
|
||||||
clock_t coolTime = clock();
|
clock_t coolTime = clock();
|
||||||
U32 testNb;
|
U32 testNb;
|
||||||
|
|
||||||
DISPLAY("\r%79s\r", "");
|
DISPLAY("\r%79s\r", "");
|
||||||
for (testNb = 1; testNb <= (g_nbIterations + !g_nbIterations); testNb++) {
|
for (testNb = 1; testNb <= (g_nbIterations + !g_nbIterations); testNb++) {
|
||||||
int nbLoops;
|
size_t cSize;
|
||||||
clock_t clockStart, clockSpan;
|
double ratio = 0.;
|
||||||
|
clock_t clockStart;
|
||||||
clock_t const clockLoop = g_nbIterations ? TIMELOOP_S * CLOCKS_PER_SEC : 10;
|
clock_t const clockLoop = g_nbIterations ? TIMELOOP_S * CLOCKS_PER_SEC : 10;
|
||||||
|
|
||||||
/* overheat protection */
|
/* overheat protection */
|
||||||
@ -266,20 +264,21 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
|||||||
clockStart = clock();
|
clockStart = clock();
|
||||||
while (clock() == clockStart);
|
while (clock() == clockStart);
|
||||||
clockStart = clock();
|
clockStart = clock();
|
||||||
|
{ U32 nbLoops;
|
||||||
for (nbLoops = 0 ; BMK_clockSpan(clockStart) < clockLoop ; nbLoops++) {
|
for (nbLoops = 0 ; BMK_clockSpan(clockStart) < clockLoop ; nbLoops++) {
|
||||||
U32 blockNb;
|
U32 blockNb;
|
||||||
ZSTD_compressBegin_usingDict(refCtx, dictBuffer, dictBufferSize, cLevel);
|
ZSTD_compressBegin_usingDict(refCtx, dictBuffer, dictBufferSize, cLevel);
|
||||||
for (blockNb=0; blockNb<nbBlocks; blockNb++) {
|
for (blockNb=0; blockNb<nbBlocks; blockNb++) {
|
||||||
size_t const rSize = ZSTD_compress_usingPreparedCCtx(ctx, refCtx,
|
size_t const rSize = ZSTD_compress_usingPreparedCCtx(ctx, refCtx,
|
||||||
blockTable[blockNb].cPtr, blockTable[blockNb].cRoom,
|
blockTable[blockNb].cPtr, blockTable[blockNb].cRoom,
|
||||||
blockTable[blockNb].srcPtr,blockTable[blockNb].srcSize);
|
blockTable[blockNb].srcPtr,blockTable[blockNb].srcSize);
|
||||||
if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_compress_usingPreparedCCtx() failed : %s", ZSTD_getErrorName(rSize));
|
if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_compress_usingPreparedCCtx() failed : %s", ZSTD_getErrorName(rSize));
|
||||||
blockTable[blockNb].cSize = rSize;
|
blockTable[blockNb].cSize = rSize;
|
||||||
|
} }
|
||||||
|
{ clock_t const clockSpan = BMK_clockSpan(clockStart);
|
||||||
|
if ((double)clockSpan < fastestC*nbLoops) fastestC = (double)clockSpan / nbLoops;
|
||||||
} }
|
} }
|
||||||
clockSpan = BMK_clockSpan(clockStart);
|
|
||||||
|
|
||||||
if ((double)clockSpan < fastestC*nbLoops) fastestC = (double)clockSpan / nbLoops;
|
|
||||||
cSize = 0;
|
cSize = 0;
|
||||||
{ U32 blockNb; for (blockNb=0; blockNb<nbBlocks; blockNb++) cSize += blockTable[blockNb].cSize; }
|
{ U32 blockNb; for (blockNb=0; blockNb<nbBlocks; blockNb++) cSize += blockTable[blockNb].cSize; }
|
||||||
ratio = (double)srcSize / (double)cSize;
|
ratio = (double)srcSize / (double)cSize;
|
||||||
@ -287,7 +286,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
|||||||
testNb, displayName, (U32)srcSize, (U32)cSize, ratio,
|
testNb, displayName, (U32)srcSize, (U32)cSize, ratio,
|
||||||
(double)srcSize / 1000000. / (fastestC / CLOCKS_PER_SEC) );
|
(double)srcSize / 1000000. / (fastestC / CLOCKS_PER_SEC) );
|
||||||
|
|
||||||
(void)crcCheck; (void)fastestD; (void)crcOrig; /* unused when decompression disabled */
|
(void)fastestD; (void)crcOrig; /* unused when decompression disabled */
|
||||||
#if 1
|
#if 1
|
||||||
/* Decompression */
|
/* Decompression */
|
||||||
memset(resultBuffer, 0xD6, srcSize); /* warm result buffer */
|
memset(resultBuffer, 0xD6, srcSize); /* warm result buffer */
|
||||||
@ -296,53 +295,54 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
|
|||||||
while (clock() == clockStart);
|
while (clock() == clockStart);
|
||||||
clockStart = clock();
|
clockStart = clock();
|
||||||
|
|
||||||
for (nbLoops = 0 ; BMK_clockSpan(clockStart) < clockLoop ; nbLoops++) {
|
{ U32 nbLoops;
|
||||||
U32 blockNb;
|
for (nbLoops = 0 ; BMK_clockSpan(clockStart) < clockLoop ; nbLoops++) {
|
||||||
ZSTD_decompressBegin_usingDict(refDCtx, dictBuffer, dictBufferSize);
|
U32 blockNb;
|
||||||
for (blockNb=0; blockNb<nbBlocks; blockNb++) {
|
ZSTD_decompressBegin_usingDict(refDCtx, dictBuffer, dictBufferSize);
|
||||||
size_t regenSize = ZSTD_decompress_usingPreparedDCtx(dctx, refDCtx,
|
for (blockNb=0; blockNb<nbBlocks; blockNb++) {
|
||||||
blockTable[blockNb].resPtr, blockTable[blockNb].srcSize,
|
size_t const regenSize = ZSTD_decompress_usingPreparedDCtx(dctx, refDCtx,
|
||||||
blockTable[blockNb].cPtr, blockTable[blockNb].cSize);
|
blockTable[blockNb].resPtr, blockTable[blockNb].srcSize,
|
||||||
if (ZSTD_isError(regenSize)) {
|
blockTable[blockNb].cPtr, blockTable[blockNb].cSize);
|
||||||
DISPLAY("ZSTD_decompress_usingPreparedDCtx() failed on block %u : %s",
|
if (ZSTD_isError(regenSize)) {
|
||||||
blockNb, ZSTD_getErrorName(regenSize));
|
DISPLAY("ZSTD_decompress_usingPreparedDCtx() failed on block %u : %s \n",
|
||||||
goto _findError;
|
blockNb, ZSTD_getErrorName(regenSize));
|
||||||
}
|
break;
|
||||||
blockTable[blockNb].resSize = regenSize;
|
}
|
||||||
|
blockTable[blockNb].resSize = regenSize;
|
||||||
|
} }
|
||||||
|
{ clock_t const clockSpan = BMK_clockSpan(clockStart);
|
||||||
|
if ((double)clockSpan < fastestD*nbLoops) fastestD = (double)clockSpan / nbLoops;
|
||||||
} }
|
} }
|
||||||
|
|
||||||
clockSpan = BMK_clockSpan(clockStart);
|
|
||||||
if ((double)clockSpan < fastestD*nbLoops) fastestD = (double)clockSpan / nbLoops;
|
|
||||||
DISPLAY("%2i-%-17.17s :%10u ->%10u (%5.3f),%6.1f MB/s ,%6.1f MB/s\r",
|
DISPLAY("%2i-%-17.17s :%10u ->%10u (%5.3f),%6.1f MB/s ,%6.1f MB/s\r",
|
||||||
testNb, displayName, (U32)srcSize, (U32)cSize, ratio,
|
testNb, displayName, (U32)srcSize, (U32)cSize, ratio,
|
||||||
(double)srcSize / 1000000. / (fastestC / CLOCKS_PER_SEC),
|
(double)srcSize / 1000000. / (fastestC / CLOCKS_PER_SEC),
|
||||||
(double)srcSize / 1000000. / (fastestD / CLOCKS_PER_SEC) );
|
(double)srcSize / 1000000. / (fastestD / CLOCKS_PER_SEC) );
|
||||||
|
|
||||||
/* CRC Checking */
|
/* CRC Checking */
|
||||||
_findError:
|
{ U64 const crcCheck = XXH64(resultBuffer, srcSize, 0);
|
||||||
crcCheck = XXH64(resultBuffer, srcSize, 0);
|
if (crcOrig!=crcCheck) {
|
||||||
if (crcOrig!=crcCheck) {
|
size_t u;
|
||||||
size_t u;
|
DISPLAY("!!! WARNING !!! %14s : Invalid Checksum : %x != %x \n", displayName, (unsigned)crcOrig, (unsigned)crcCheck);
|
||||||
DISPLAY("\n!!! WARNING !!! %14s : Invalid Checksum : %x != %x\n", displayName, (unsigned)crcOrig, (unsigned)crcCheck);
|
for (u=0; u<srcSize; u++) {
|
||||||
for (u=0; u<srcSize; u++) {
|
if (((const BYTE*)srcBuffer)[u] != ((const BYTE*)resultBuffer)[u]) {
|
||||||
if (((const BYTE*)srcBuffer)[u] != ((const BYTE*)resultBuffer)[u]) {
|
U32 segNb, bNb, pos;
|
||||||
U32 segNb, bNb, pos;
|
size_t bacc = 0;
|
||||||
size_t bacc = 0;
|
DISPLAY("Decoding error at pos %u ", (U32)u);
|
||||||
printf("Decoding error at pos %u ", (U32)u);
|
for (segNb = 0; segNb < nbBlocks; segNb++) {
|
||||||
for (segNb = 0; segNb < nbBlocks; segNb++) {
|
if (bacc + blockTable[segNb].srcSize > u) break;
|
||||||
if (bacc + blockTable[segNb].srcSize > u) break;
|
bacc += blockTable[segNb].srcSize;
|
||||||
bacc += blockTable[segNb].srcSize;
|
}
|
||||||
|
pos = (U32)(u - bacc);
|
||||||
|
bNb = pos / (128 KB);
|
||||||
|
DISPLAY("(block %u, sub %u, pos %u) \n", segNb, bNb, pos);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
pos = (U32)(u - bacc);
|
if (u==srcSize-1) { /* should never happen */
|
||||||
bNb = pos / (128 KB);
|
DISPLAY("no difference detected\n");
|
||||||
printf("(block %u, sub %u, pos %u) \n", segNb, bNb, pos);
|
} }
|
||||||
break;
|
break;
|
||||||
}
|
} } /* CRC Checking */
|
||||||
if (u==srcSize-1) { /* should never happen */
|
|
||||||
printf("no difference detected\n");
|
|
||||||
} }
|
|
||||||
break;
|
|
||||||
} /* if (crcOrig!=crcCheck) */
|
|
||||||
#endif
|
#endif
|
||||||
} /* for (testNb = 1; testNb <= (g_nbIterations + !g_nbIterations); testNb++) */
|
} /* for (testNb = 1; testNb <= (g_nbIterations + !g_nbIterations); testNb++) */
|
||||||
DISPLAY("%2i#\n", cLevel);
|
DISPLAY("%2i#\n", cLevel);
|
||||||
@ -407,23 +407,25 @@ static U64 BMK_getTotalFileSize(const char** fileNamesTable, unsigned nbFiles)
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! 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,
|
static void BMK_loadFiles(void* buffer, size_t bufferSize,
|
||||||
size_t* fileSizes,
|
size_t* fileSizes,
|
||||||
const char** fileNamesTable, unsigned const nbFiles)
|
const char** fileNamesTable, unsigned nbFiles)
|
||||||
{
|
{
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
|
|
||||||
unsigned n;
|
unsigned n;
|
||||||
for (n=0; n<nbFiles; n++) {
|
for (n=0; n<nbFiles; n++) {
|
||||||
size_t readSize;
|
|
||||||
U64 fileSize = BMK_getFileSize(fileNamesTable[n]);
|
U64 fileSize = BMK_getFileSize(fileNamesTable[n]);
|
||||||
FILE* f = fopen(fileNamesTable[n], "rb");
|
FILE* const f = fopen(fileNamesTable[n], "rb");
|
||||||
if (f==NULL) EXM_THROW(10, "impossible to open file %s", fileNamesTable[n]);
|
if (f==NULL) EXM_THROW(10, "impossible to open file %s", fileNamesTable[n]);
|
||||||
DISPLAYLEVEL(2, "Loading %s... \r", fileNamesTable[n]);
|
DISPLAYLEVEL(2, "Loading %s... \r", fileNamesTable[n]);
|
||||||
if (fileSize > bufferSize-pos) fileSize = bufferSize-pos;
|
if (fileSize > bufferSize-pos) fileSize = bufferSize-pos, nbFiles=n; /* buffer too small - stop after this file */
|
||||||
readSize = fread(((char*)buffer)+pos, 1, (size_t)fileSize, f);
|
{ 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]);
|
if (readSize != (size_t)fileSize) EXM_THROW(11, "could not read %s", fileNamesTable[n]);
|
||||||
pos += readSize;
|
pos += readSize; }
|
||||||
fileSizes[n] = (size_t)fileSize;
|
fileSizes[n] = (size_t)fileSize;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user