diff --git a/programs/bench.c b/programs/bench.c index 905f84ed..2bde4c03 100644 --- a/programs/bench.c +++ b/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); /* Bench */ - { size_t cSize = 0; - double fastestC = 100000000., fastestD = 100000000.; - double ratio = 0.; - U64 crcCheck = 0; + { double fastestC = 100000000., fastestD = 100000000.; clock_t coolTime = clock(); U32 testNb; DISPLAY("\r%79s\r", ""); for (testNb = 1; testNb <= (g_nbIterations + !g_nbIterations); testNb++) { - int nbLoops; - clock_t clockStart, clockSpan; + size_t cSize; + double ratio = 0.; + clock_t clockStart; clock_t const clockLoop = g_nbIterations ? TIMELOOP_S * CLOCKS_PER_SEC : 10; /* overheat protection */ @@ -266,20 +264,21 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, clockStart = clock(); while (clock() == clockStart); clockStart = clock(); - - for (nbLoops = 0 ; BMK_clockSpan(clockStart) < clockLoop ; nbLoops++) { - U32 blockNb; - ZSTD_compressBegin_usingDict(refCtx, dictBuffer, dictBufferSize, cLevel); - for (blockNb=0; blockNb%10u (%5.3f),%6.1f MB/s ,%6.1f MB/s\r", testNb, displayName, (U32)srcSize, (U32)cSize, ratio, (double)srcSize / 1000000. / (fastestC / CLOCKS_PER_SEC), (double)srcSize / 1000000. / (fastestD / CLOCKS_PER_SEC) ); /* CRC Checking */ -_findError: - crcCheck = XXH64(resultBuffer, srcSize, 0); - if (crcOrig!=crcCheck) { - size_t u; - DISPLAY("\n!!! WARNING !!! %14s : Invalid Checksum : %x != %x\n", displayName, (unsigned)crcOrig, (unsigned)crcCheck); - for (u=0; u u) break; - bacc += blockTable[segNb].srcSize; + { U64 const crcCheck = XXH64(resultBuffer, srcSize, 0); + if (crcOrig!=crcCheck) { + size_t u; + DISPLAY("!!! WARNING !!! %14s : Invalid Checksum : %x != %x \n", displayName, (unsigned)crcOrig, (unsigned)crcCheck); + for (u=0; u 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; } - pos = (U32)(u - bacc); - bNb = pos / (128 KB); - printf("(block %u, sub %u, pos %u) \n", segNb, bNb, pos); - break; - } - if (u==srcSize-1) { /* should never happen */ - printf("no difference detected\n"); - } } - break; - } /* if (crcOrig!=crcCheck) */ + if (u==srcSize-1) { /* should never happen */ + DISPLAY("no difference detected\n"); + } } + break; + } } /* CRC Checking */ #endif } /* for (testNb = 1; testNb <= (g_nbIterations + !g_nbIterations); testNb++) */ DISPLAY("%2i#\n", cLevel); @@ -407,23 +407,25 @@ static U64 BMK_getTotalFileSize(const char** fileNamesTable, unsigned nbFiles) 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, size_t* fileSizes, - const char** fileNamesTable, unsigned const nbFiles) + const char** fileNamesTable, unsigned nbFiles) { size_t pos = 0; unsigned n; for (n=0; n bufferSize-pos) fileSize = bufferSize-pos; - 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; + if (fileSize > bufferSize-pos) fileSize = bufferSize-pos, nbFiles=n; /* buffer too small - stop after this file */ + { 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; fclose(f); }