| 149 | |
| 150 | |
| 151 | static int BMK_benchMem(z_const void* srcBuffer, size_t srcSize, |
| 152 | const char* displayName, int cLevel, |
| 153 | const size_t* fileSizes, U32 nbFiles, |
| 154 | const void* dictBuffer, size_t dictBufferSize, BMK_compressor compressor) |
| 155 | { |
| 156 | size_t const blockSize = (g_blockSize>=32 ? g_blockSize : srcSize) + (!srcSize) /* avoid div by 0 */ ; |
| 157 | size_t const avgSize = MIN(g_blockSize, (srcSize / nbFiles)); |
| 158 | U32 const maxNbBlocks = (U32) ((srcSize + (blockSize-1)) / blockSize) + nbFiles; |
| 159 | blockParam_t* const blockTable = (blockParam_t*) malloc(maxNbBlocks * sizeof(blockParam_t)); |
| 160 | size_t const maxCompressedSize = ZSTD_compressBound(srcSize) + (maxNbBlocks * 1024); /* add some room for safety */ |
| 161 | void* const compressedBuffer = malloc(maxCompressedSize); |
| 162 | void* const resultBuffer = malloc(srcSize); |
| 163 | ZSTD_CCtx* const ctx = ZSTD_createCCtx(); |
| 164 | ZSTD_DCtx* const dctx = ZSTD_createDCtx(); |
| 165 | U32 nbBlocks; |
| 166 | |
| 167 | /* checks */ |
| 168 | if (!compressedBuffer || !resultBuffer || !blockTable || !ctx || !dctx) |
| 169 | EXM_THROW(31, "allocation error : not enough memory"); |
| 170 | |
| 171 | /* init */ |
| 172 | if (strlen(displayName)>17) displayName += strlen(displayName)-17; /* can only display 17 characters */ |
| 173 | |
| 174 | /* Init blockTable data */ |
| 175 | { z_const char* srcPtr = (z_const char*)srcBuffer; |
| 176 | char* cPtr = (char*)compressedBuffer; |
| 177 | char* resPtr = (char*)resultBuffer; |
| 178 | U32 fileNb; |
| 179 | for (nbBlocks=0, fileNb=0; fileNb<nbFiles; fileNb++) { |
| 180 | size_t remaining = fileSizes[fileNb]; |
| 181 | U32 const nbBlocksforThisFile = (U32)((remaining + (blockSize-1)) / blockSize); |
| 182 | U32 const blockEnd = nbBlocks + nbBlocksforThisFile; |
| 183 | for ( ; nbBlocks<blockEnd; nbBlocks++) { |
| 184 | size_t const thisBlockSize = MIN(remaining, blockSize); |
| 185 | blockTable[nbBlocks].srcPtr = srcPtr; |
| 186 | blockTable[nbBlocks].cPtr = cPtr; |
| 187 | blockTable[nbBlocks].resPtr = resPtr; |
| 188 | blockTable[nbBlocks].srcSize = thisBlockSize; |
| 189 | blockTable[nbBlocks].cRoom = ZSTD_compressBound(thisBlockSize); |
| 190 | srcPtr += thisBlockSize; |
| 191 | cPtr += blockTable[nbBlocks].cRoom; |
| 192 | resPtr += thisBlockSize; |
| 193 | remaining -= thisBlockSize; |
| 194 | } } } |
| 195 | |
| 196 | /* warming up memory */ |
| 197 | RDG_genBuffer(compressedBuffer, maxCompressedSize, 0.10, 0.50, 1); |
| 198 | |
| 199 | /* Bench */ |
| 200 | { U64 fastestC = (U64)(-1LL), fastestD = (U64)(-1LL); |
| 201 | U64 const crcOrig = XXH64(srcBuffer, srcSize, 0); |
| 202 | UTIL_time_t coolTime; |
| 203 | U64 const maxTime = (g_nbIterations * TIMELOOP_MICROSEC) + 100; |
| 204 | U64 totalCTime=0, totalDTime=0; |
| 205 | U32 cCompleted=0, dCompleted=0; |
| 206 | # define NB_MARKS 4 |
| 207 | const char* const marks[NB_MARKS] = { " |", " /", " =", "\\" }; |
| 208 | U32 markNb = 0; |
no test coverage detected