inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2016-present, Yann Collet, Przemyslaw Skibinski, Facebook, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This source code is licensed under the BSD-style license found in the |
| 6 | * LICENSE file in the root directory of this source tree. An additional grant |
| 7 | * of patent rights can be found in the PATENTS file in the same directory. |
| 8 | */ |
| 9 | |
| 10 | |
| 11 | /* ************************************* |
| 12 | * Includes |
| 13 | ***************************************/ |
| 14 | #include "util.h" /* Compiler options, UTIL_GetFileSize, UTIL_sleep */ |
| 15 | #include <stdlib.h> /* malloc, free */ |
| 16 | #include <string.h> /* memset */ |
| 17 | #include <stdio.h> /* fprintf, fopen, ftello64 */ |
| 18 | #include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */ |
inikep | b88accf | 2016-09-23 13:38:02 +0200 | [diff] [blame] | 19 | #include <ctype.h> /* toupper */ |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 20 | |
| 21 | #include "mem.h" |
| 22 | #define ZSTD_STATIC_LINKING_ONLY |
| 23 | #include "zstd.h" |
| 24 | #include "datagen.h" /* RDG_genBuffer */ |
| 25 | #include "xxhash.h" |
| 26 | |
inikep | 8e8b046 | 2016-09-22 14:42:32 +0200 | [diff] [blame] | 27 | #include "zstd_zlibwrapper.h" |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 28 | |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 29 | |
| 30 | |
| 31 | /*-************************************ |
| 32 | * Tuning parameters |
| 33 | **************************************/ |
| 34 | #ifndef ZSTDCLI_CLEVEL_DEFAULT |
| 35 | # define ZSTDCLI_CLEVEL_DEFAULT 3 |
| 36 | #endif |
| 37 | |
| 38 | |
| 39 | |
| 40 | /*-************************************ |
| 41 | * Constants |
| 42 | **************************************/ |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 43 | #define COMPRESSOR_NAME "Zstandard wrapper for zlib command line interface" |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 44 | #ifndef ZSTD_VERSION |
| 45 | # define ZSTD_VERSION "v" ZSTD_VERSION_STRING |
| 46 | #endif |
| 47 | #define AUTHOR "Yann Collet" |
| 48 | #define WELCOME_MESSAGE "*** %s %i-bits %s, by %s ***\n", COMPRESSOR_NAME, (int)(sizeof(size_t)*8), ZSTD_VERSION, AUTHOR |
| 49 | |
| 50 | #ifndef ZSTD_GIT_COMMIT |
| 51 | # define ZSTD_GIT_COMMIT_STRING "" |
| 52 | #else |
| 53 | # define ZSTD_GIT_COMMIT_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_GIT_COMMIT) |
| 54 | #endif |
| 55 | |
| 56 | #define NBLOOPS 3 |
| 57 | #define TIMELOOP_MICROSEC 1*1000000ULL /* 1 second */ |
| 58 | #define ACTIVEPERIOD_MICROSEC 70*1000000ULL /* 70 seconds */ |
| 59 | #define COOLPERIOD_SEC 10 |
| 60 | |
| 61 | #define KB *(1 <<10) |
| 62 | #define MB *(1 <<20) |
| 63 | #define GB *(1U<<30) |
| 64 | |
| 65 | static const size_t maxMemory = (sizeof(size_t)==4) ? (2 GB - 64 MB) : (size_t)(1ULL << ((sizeof(size_t)*8)-31)); |
| 66 | |
| 67 | static U32 g_compressibilityDefault = 50; |
| 68 | |
| 69 | |
| 70 | /* ************************************* |
| 71 | * console display |
| 72 | ***************************************/ |
| 73 | #define DEFAULT_DISPLAY_LEVEL 2 |
| 74 | #define DISPLAY(...) fprintf(displayOut, __VA_ARGS__) |
| 75 | #define DISPLAYLEVEL(l, ...) if (g_displayLevel>=l) { DISPLAY(__VA_ARGS__); } |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 76 | static int g_displayLevel = DEFAULT_DISPLAY_LEVEL; /* 0 : no display; 1: errors; 2 : + result + interaction + warnings; 3 : + progression; 4 : + information */ |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 77 | static FILE* displayOut; |
| 78 | |
| 79 | #define DISPLAYUPDATE(l, ...) if (g_displayLevel>=l) { \ |
| 80 | if ((clock() - g_time > refreshRate) || (g_displayLevel>=4)) \ |
| 81 | { g_time = clock(); DISPLAY(__VA_ARGS__); \ |
Sean Purcell | 042ba12 | 2017-03-23 11:13:52 -0700 | [diff] [blame] | 82 | if (g_displayLevel>=4) fflush(displayOut); } } |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 83 | static const clock_t refreshRate = CLOCKS_PER_SEC * 15 / 100; |
| 84 | static clock_t g_time = 0; |
| 85 | |
| 86 | |
| 87 | /* ************************************* |
| 88 | * Exceptions |
| 89 | ***************************************/ |
| 90 | #ifndef DEBUG |
| 91 | # define DEBUG 0 |
| 92 | #endif |
Yann Collet | 7bd1a29 | 2017-06-21 11:50:33 -0700 | [diff] [blame^] | 93 | #define DEBUGOUTPUT(...) { if (DEBUG) DISPLAY(__VA_ARGS__); } |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 94 | #define EXM_THROW(error, ...) \ |
| 95 | { \ |
| 96 | DEBUGOUTPUT("Error defined at %s, line %i : \n", __FILE__, __LINE__); \ |
| 97 | DISPLAYLEVEL(1, "Error %i : ", error); \ |
| 98 | DISPLAYLEVEL(1, __VA_ARGS__); \ |
| 99 | DISPLAYLEVEL(1, "\n"); \ |
| 100 | exit(error); \ |
| 101 | } |
| 102 | |
| 103 | |
| 104 | /* ************************************* |
| 105 | * Benchmark Parameters |
| 106 | ***************************************/ |
| 107 | static U32 g_nbIterations = NBLOOPS; |
| 108 | static size_t g_blockSize = 0; |
| 109 | int g_additionalParam = 0; |
| 110 | |
| 111 | void BMK_setNotificationLevel(unsigned level) { g_displayLevel=level; } |
| 112 | |
| 113 | void BMK_setAdditionalParam(int additionalParam) { g_additionalParam=additionalParam; } |
| 114 | |
| 115 | void BMK_SetNbIterations(unsigned nbLoops) |
| 116 | { |
| 117 | g_nbIterations = nbLoops; |
| 118 | DISPLAYLEVEL(3, "- test >= %u seconds per compression / decompression -\n", g_nbIterations); |
| 119 | } |
| 120 | |
| 121 | void BMK_SetBlockSize(size_t blockSize) |
| 122 | { |
| 123 | g_blockSize = blockSize; |
| 124 | DISPLAYLEVEL(2, "using blocks of size %u KB \n", (U32)(blockSize>>10)); |
| 125 | } |
| 126 | |
| 127 | |
| 128 | /* ******************************************************** |
| 129 | * Bench functions |
| 130 | **********************************************************/ |
Yann Collet | 4f81818 | 2017-04-17 17:57:35 -0700 | [diff] [blame] | 131 | #undef MIN |
| 132 | #undef MAX |
| 133 | #define MIN(a,b) ((a)<(b) ? (a) : (b)) |
| 134 | #define MAX(a,b) ((a)>(b) ? (a) : (b)) |
| 135 | |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 136 | typedef struct |
| 137 | { |
Przemyslaw Skibinski | 6cecb35 | 2016-11-04 17:49:17 +0100 | [diff] [blame] | 138 | z_const char* srcPtr; |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 139 | size_t srcSize; |
| 140 | char* cPtr; |
| 141 | size_t cRoom; |
| 142 | size_t cSize; |
| 143 | char* resPtr; |
| 144 | size_t resSize; |
| 145 | } blockParam_t; |
| 146 | |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 147 | typedef enum { BMK_ZSTD, BMK_ZSTD_STREAM, BMK_ZLIB, BMK_ZWRAP_ZLIB, BMK_ZWRAP_ZSTD, BMK_ZLIB_REUSE, BMK_ZWRAP_ZLIB_REUSE, BMK_ZWRAP_ZSTD_REUSE } BMK_compressor; |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 148 | |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 149 | |
Przemyslaw Skibinski | 6cecb35 | 2016-11-04 17:49:17 +0100 | [diff] [blame] | 150 | static int BMK_benchMem(z_const void* srcBuffer, size_t srcSize, |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 151 | const char* displayName, int cLevel, |
| 152 | const size_t* fileSizes, U32 nbFiles, |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 153 | const void* dictBuffer, size_t dictBufferSize, BMK_compressor compressor) |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 154 | { |
| 155 | size_t const blockSize = (g_blockSize>=32 ? g_blockSize : srcSize) + (!srcSize) /* avoid div by 0 */ ; |
| 156 | size_t const avgSize = MIN(g_blockSize, (srcSize / nbFiles)); |
| 157 | U32 const maxNbBlocks = (U32) ((srcSize + (blockSize-1)) / blockSize) + nbFiles; |
| 158 | blockParam_t* const blockTable = (blockParam_t*) malloc(maxNbBlocks * sizeof(blockParam_t)); |
| 159 | size_t const maxCompressedSize = ZSTD_compressBound(srcSize) + (maxNbBlocks * 1024); /* add some room for safety */ |
| 160 | void* const compressedBuffer = malloc(maxCompressedSize); |
| 161 | void* const resultBuffer = malloc(srcSize); |
| 162 | ZSTD_CCtx* const ctx = ZSTD_createCCtx(); |
| 163 | ZSTD_DCtx* const dctx = ZSTD_createDCtx(); |
| 164 | U32 nbBlocks; |
Przemyslaw Skibinski | e052c60 | 2017-02-20 11:27:11 +0100 | [diff] [blame] | 165 | UTIL_freq_t ticksPerSecond; |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 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 | UTIL_initTimer(&ticksPerSecond); |
| 174 | |
| 175 | /* Init blockTable data */ |
Przemyslaw Skibinski | 6cecb35 | 2016-11-04 17:49:17 +0100 | [diff] [blame] | 176 | { z_const char* srcPtr = (z_const char*)srcBuffer; |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 177 | char* cPtr = (char*)compressedBuffer; |
| 178 | char* resPtr = (char*)resultBuffer; |
| 179 | U32 fileNb; |
| 180 | for (nbBlocks=0, fileNb=0; fileNb<nbFiles; fileNb++) { |
| 181 | size_t remaining = fileSizes[fileNb]; |
| 182 | U32 const nbBlocksforThisFile = (U32)((remaining + (blockSize-1)) / blockSize); |
| 183 | U32 const blockEnd = nbBlocks + nbBlocksforThisFile; |
| 184 | for ( ; nbBlocks<blockEnd; nbBlocks++) { |
| 185 | size_t const thisBlockSize = MIN(remaining, blockSize); |
| 186 | blockTable[nbBlocks].srcPtr = srcPtr; |
| 187 | blockTable[nbBlocks].cPtr = cPtr; |
| 188 | blockTable[nbBlocks].resPtr = resPtr; |
| 189 | blockTable[nbBlocks].srcSize = thisBlockSize; |
| 190 | blockTable[nbBlocks].cRoom = ZSTD_compressBound(thisBlockSize); |
| 191 | srcPtr += thisBlockSize; |
| 192 | cPtr += blockTable[nbBlocks].cRoom; |
| 193 | resPtr += thisBlockSize; |
| 194 | remaining -= thisBlockSize; |
| 195 | } } } |
| 196 | |
| 197 | /* warmimg up memory */ |
| 198 | RDG_genBuffer(compressedBuffer, maxCompressedSize, 0.10, 0.50, 1); |
| 199 | |
| 200 | /* Bench */ |
| 201 | { U64 fastestC = (U64)(-1LL), fastestD = (U64)(-1LL); |
| 202 | U64 const crcOrig = XXH64(srcBuffer, srcSize, 0); |
| 203 | UTIL_time_t coolTime; |
| 204 | U64 const maxTime = (g_nbIterations * TIMELOOP_MICROSEC) + 100; |
| 205 | U64 totalCTime=0, totalDTime=0; |
| 206 | U32 cCompleted=0, dCompleted=0; |
| 207 | # define NB_MARKS 4 |
| 208 | const char* const marks[NB_MARKS] = { " |", " /", " =", "\\" }; |
| 209 | U32 markNb = 0; |
| 210 | size_t cSize = 0; |
| 211 | double ratio = 0.; |
| 212 | |
| 213 | UTIL_getTime(&coolTime); |
| 214 | DISPLAYLEVEL(2, "\r%79s\r", ""); |
| 215 | while (!cCompleted | !dCompleted) { |
| 216 | UTIL_time_t clockStart; |
| 217 | U64 clockLoop = g_nbIterations ? TIMELOOP_MICROSEC : 1; |
| 218 | |
| 219 | /* overheat protection */ |
| 220 | if (UTIL_clockSpanMicro(coolTime, ticksPerSecond) > ACTIVEPERIOD_MICROSEC) { |
| 221 | DISPLAYLEVEL(2, "\rcooling down ... \r"); |
| 222 | UTIL_sleep(COOLPERIOD_SEC); |
| 223 | UTIL_getTime(&coolTime); |
| 224 | } |
| 225 | |
| 226 | /* Compression */ |
| 227 | DISPLAYLEVEL(2, "%2s-%-17.17s :%10u ->\r", marks[markNb], displayName, (U32)srcSize); |
| 228 | if (!cCompleted) memset(compressedBuffer, 0xE5, maxCompressedSize); /* warm up and erase result buffer */ |
| 229 | |
| 230 | UTIL_sleepMilli(1); /* give processor time to other processes */ |
| 231 | UTIL_waitForNextTick(ticksPerSecond); |
| 232 | UTIL_getTime(&clockStart); |
| 233 | |
| 234 | if (!cCompleted) { /* still some time to do compression tests */ |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 235 | U32 nbLoops = 0; |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 236 | if (compressor == BMK_ZSTD) { |
| 237 | ZSTD_parameters const zparams = ZSTD_getParams(cLevel, avgSize, dictBufferSize); |
| 238 | ZSTD_customMem const cmem = { NULL, NULL, NULL }; |
Yann Collet | 7bd1a29 | 2017-06-21 11:50:33 -0700 | [diff] [blame^] | 239 | ZSTD_CDict* const cdict = ZSTD_createCDict_advanced(dictBuffer, dictBufferSize, 1 /*byRef*/, ZSTD_dm_auto, zparams.cParams, cmem); |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 240 | if (cdict==NULL) EXM_THROW(1, "ZSTD_createCDict_advanced() allocation failure"); |
inikep | 8e8b046 | 2016-09-22 14:42:32 +0200 | [diff] [blame] | 241 | |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 242 | do { |
| 243 | U32 blockNb; |
Przemyslaw Skibinski | 96fca2b | 2016-11-25 14:36:27 +0100 | [diff] [blame] | 244 | size_t rSize; |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 245 | for (blockNb=0; blockNb<nbBlocks; blockNb++) { |
Przemyslaw Skibinski | 96fca2b | 2016-11-25 14:36:27 +0100 | [diff] [blame] | 246 | if (dictBufferSize) { |
| 247 | rSize = ZSTD_compress_usingCDict(ctx, |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 248 | blockTable[blockNb].cPtr, blockTable[blockNb].cRoom, |
| 249 | blockTable[blockNb].srcPtr,blockTable[blockNb].srcSize, |
| 250 | cdict); |
Przemyslaw Skibinski | 96fca2b | 2016-11-25 14:36:27 +0100 | [diff] [blame] | 251 | } else { |
| 252 | rSize = ZSTD_compressCCtx (ctx, |
| 253 | blockTable[blockNb].cPtr, blockTable[blockNb].cRoom, |
| 254 | blockTable[blockNb].srcPtr,blockTable[blockNb].srcSize, cLevel); |
| 255 | } |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 256 | if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_compress_usingCDict() failed : %s", ZSTD_getErrorName(rSize)); |
| 257 | blockTable[blockNb].cSize = rSize; |
| 258 | } |
| 259 | nbLoops++; |
| 260 | } while (UTIL_clockSpanMicro(clockStart, ticksPerSecond) < clockLoop); |
| 261 | ZSTD_freeCDict(cdict); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 262 | } else if (compressor == BMK_ZSTD_STREAM) { |
inikep | 8e8b046 | 2016-09-22 14:42:32 +0200 | [diff] [blame] | 263 | ZSTD_parameters const zparams = ZSTD_getParams(cLevel, avgSize, dictBufferSize); |
| 264 | ZSTD_inBuffer inBuffer; |
| 265 | ZSTD_outBuffer outBuffer; |
| 266 | ZSTD_CStream* zbc = ZSTD_createCStream(); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 267 | size_t rSize; |
inikep | 8e8b046 | 2016-09-22 14:42:32 +0200 | [diff] [blame] | 268 | if (zbc == NULL) EXM_THROW(1, "ZSTD_createCStream() allocation failure"); |
inikep | a03b7a7 | 2016-09-26 22:11:55 +0200 | [diff] [blame] | 269 | rSize = ZSTD_initCStream_advanced(zbc, dictBuffer, dictBufferSize, zparams, avgSize); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 270 | if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_initCStream_advanced() failed : %s", ZSTD_getErrorName(rSize)); |
inikep | 8e8b046 | 2016-09-22 14:42:32 +0200 | [diff] [blame] | 271 | do { |
| 272 | U32 blockNb; |
| 273 | for (blockNb=0; blockNb<nbBlocks; blockNb++) { |
inikep | cf3ec08 | 2016-09-23 10:30:26 +0200 | [diff] [blame] | 274 | rSize = ZSTD_resetCStream(zbc, blockTable[blockNb].srcSize); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 275 | if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_resetCStream() failed : %s", ZSTD_getErrorName(rSize)); |
inikep | 8e8b046 | 2016-09-22 14:42:32 +0200 | [diff] [blame] | 276 | inBuffer.src = blockTable[blockNb].srcPtr; |
| 277 | inBuffer.size = blockTable[blockNb].srcSize; |
| 278 | inBuffer.pos = 0; |
| 279 | outBuffer.dst = blockTable[blockNb].cPtr; |
| 280 | outBuffer.size = blockTable[blockNb].cRoom; |
| 281 | outBuffer.pos = 0; |
| 282 | rSize = ZSTD_compressStream(zbc, &outBuffer, &inBuffer); |
| 283 | if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_compressStream() failed : %s", ZSTD_getErrorName(rSize)); |
| 284 | rSize = ZSTD_endStream(zbc, &outBuffer); |
| 285 | if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_endStream() failed : %s", ZSTD_getErrorName(rSize)); |
| 286 | blockTable[blockNb].cSize = outBuffer.pos; |
| 287 | } |
| 288 | nbLoops++; |
| 289 | } while (UTIL_clockSpanMicro(clockStart, ticksPerSecond) < clockLoop); |
| 290 | ZSTD_freeCStream(zbc); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 291 | } else if (compressor == BMK_ZWRAP_ZLIB_REUSE || compressor == BMK_ZWRAP_ZSTD_REUSE || compressor == BMK_ZLIB_REUSE) { |
| 292 | z_stream def; |
| 293 | int ret; |
inikep | 706876f | 2016-09-27 16:56:07 +0200 | [diff] [blame] | 294 | int useSetDict = (dictBuffer != NULL); |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 295 | if (compressor == BMK_ZLIB_REUSE || compressor == BMK_ZWRAP_ZLIB_REUSE) ZWRAP_useZSTDcompression(0); |
| 296 | else ZWRAP_useZSTDcompression(1); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 297 | def.zalloc = Z_NULL; |
| 298 | def.zfree = Z_NULL; |
| 299 | def.opaque = Z_NULL; |
| 300 | ret = deflateInit(&def, cLevel); |
| 301 | if (ret != Z_OK) EXM_THROW(1, "deflateInit failure"); |
inikep | cf3ec08 | 2016-09-23 10:30:26 +0200 | [diff] [blame] | 302 | /* if (ZWRAP_isUsingZSTDcompression()) { |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 303 | ret = ZWRAP_setPledgedSrcSize(&def, avgSize); |
| 304 | if (ret != Z_OK) EXM_THROW(1, "ZWRAP_setPledgedSrcSize failure"); |
inikep | 2bb83e8 | 2016-09-23 18:59:53 +0200 | [diff] [blame] | 305 | } */ |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 306 | do { |
| 307 | U32 blockNb; |
| 308 | for (blockNb=0; blockNb<nbBlocks; blockNb++) { |
inikep | 706876f | 2016-09-27 16:56:07 +0200 | [diff] [blame] | 309 | if (ZWRAP_isUsingZSTDcompression()) |
inikep | 20859af | 2016-09-27 17:27:43 +0200 | [diff] [blame] | 310 | ret = ZWRAP_deflateReset_keepDict(&def); /* reuse dictionary to make compression faster */ |
inikep | 706876f | 2016-09-27 16:56:07 +0200 | [diff] [blame] | 311 | else |
| 312 | ret = deflateReset(&def); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 313 | if (ret != Z_OK) EXM_THROW(1, "deflateReset failure"); |
inikep | 706876f | 2016-09-27 16:56:07 +0200 | [diff] [blame] | 314 | if (useSetDict) { |
inikep | a03b7a7 | 2016-09-26 22:11:55 +0200 | [diff] [blame] | 315 | ret = deflateSetDictionary(&def, dictBuffer, dictBufferSize); |
| 316 | if (ret != Z_OK) EXM_THROW(1, "deflateSetDictionary failure"); |
inikep | 20859af | 2016-09-27 17:27:43 +0200 | [diff] [blame] | 317 | if (ZWRAP_isUsingZSTDcompression()) useSetDict = 0; /* zstd doesn't require deflateSetDictionary after ZWRAP_deflateReset_keepDict */ |
inikep | a03b7a7 | 2016-09-26 22:11:55 +0200 | [diff] [blame] | 318 | } |
Przemyslaw Skibinski | 6cecb35 | 2016-11-04 17:49:17 +0100 | [diff] [blame] | 319 | def.next_in = (z_const void*) blockTable[blockNb].srcPtr; |
Yann Collet | 9ceb49e | 2016-12-22 15:26:33 +0100 | [diff] [blame] | 320 | def.avail_in = (uInt)blockTable[blockNb].srcSize; |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 321 | def.total_in = 0; |
| 322 | def.next_out = (void*) blockTable[blockNb].cPtr; |
Yann Collet | 9ceb49e | 2016-12-22 15:26:33 +0100 | [diff] [blame] | 323 | def.avail_out = (uInt)blockTable[blockNb].cRoom; |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 324 | def.total_out = 0; |
| 325 | ret = deflate(&def, Z_FINISH); |
inikep | 2bb83e8 | 2016-09-23 18:59:53 +0200 | [diff] [blame] | 326 | if (ret != Z_STREAM_END) EXM_THROW(1, "deflate failure ret=%d srcSize=%d" , ret, (int)blockTable[blockNb].srcSize); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 327 | blockTable[blockNb].cSize = def.total_out; |
| 328 | } |
| 329 | nbLoops++; |
| 330 | } while (UTIL_clockSpanMicro(clockStart, ticksPerSecond) < clockLoop); |
| 331 | ret = deflateEnd(&def); |
| 332 | if (ret != Z_OK) EXM_THROW(1, "deflateEnd failure"); |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 333 | } else { |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 334 | z_stream def; |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 335 | if (compressor == BMK_ZLIB || compressor == BMK_ZWRAP_ZLIB) ZWRAP_useZSTDcompression(0); |
| 336 | else ZWRAP_useZSTDcompression(1); |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 337 | do { |
| 338 | U32 blockNb; |
| 339 | for (blockNb=0; blockNb<nbBlocks; blockNb++) { |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 340 | int ret; |
| 341 | def.zalloc = Z_NULL; |
| 342 | def.zfree = Z_NULL; |
| 343 | def.opaque = Z_NULL; |
| 344 | ret = deflateInit(&def, cLevel); |
| 345 | if (ret != Z_OK) EXM_THROW(1, "deflateInit failure"); |
inikep | a03b7a7 | 2016-09-26 22:11:55 +0200 | [diff] [blame] | 346 | if (dictBuffer) { |
| 347 | ret = deflateSetDictionary(&def, dictBuffer, dictBufferSize); |
| 348 | if (ret != Z_OK) EXM_THROW(1, "deflateSetDictionary failure"); |
| 349 | } |
Przemyslaw Skibinski | 6cecb35 | 2016-11-04 17:49:17 +0100 | [diff] [blame] | 350 | def.next_in = (z_const void*) blockTable[blockNb].srcPtr; |
Yann Collet | 9ceb49e | 2016-12-22 15:26:33 +0100 | [diff] [blame] | 351 | def.avail_in = (uInt)blockTable[blockNb].srcSize; |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 352 | def.total_in = 0; |
| 353 | def.next_out = (void*) blockTable[blockNb].cPtr; |
Yann Collet | 9ceb49e | 2016-12-22 15:26:33 +0100 | [diff] [blame] | 354 | def.avail_out = (uInt)blockTable[blockNb].cRoom; |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 355 | def.total_out = 0; |
| 356 | ret = deflate(&def, Z_FINISH); |
| 357 | if (ret != Z_STREAM_END) EXM_THROW(1, "deflate failure"); |
| 358 | ret = deflateEnd(&def); |
| 359 | if (ret != Z_OK) EXM_THROW(1, "deflateEnd failure"); |
| 360 | blockTable[blockNb].cSize = def.total_out; |
| 361 | } |
| 362 | nbLoops++; |
| 363 | } while (UTIL_clockSpanMicro(clockStart, ticksPerSecond) < clockLoop); |
| 364 | } |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 365 | { U64 const clockSpan = UTIL_clockSpanMicro(clockStart, ticksPerSecond); |
| 366 | if (clockSpan < fastestC*nbLoops) fastestC = clockSpan / nbLoops; |
| 367 | totalCTime += clockSpan; |
| 368 | cCompleted = totalCTime>maxTime; |
| 369 | } } |
| 370 | |
| 371 | cSize = 0; |
| 372 | { U32 blockNb; for (blockNb=0; blockNb<nbBlocks; blockNb++) cSize += blockTable[blockNb].cSize; } |
| 373 | ratio = (double)srcSize / (double)cSize; |
| 374 | markNb = (markNb+1) % NB_MARKS; |
| 375 | DISPLAYLEVEL(2, "%2s-%-17.17s :%10u ->%10u (%5.3f),%6.1f MB/s\r", |
| 376 | marks[markNb], displayName, (U32)srcSize, (U32)cSize, ratio, |
| 377 | (double)srcSize / fastestC ); |
| 378 | |
| 379 | (void)fastestD; (void)crcOrig; /* unused when decompression disabled */ |
| 380 | #if 1 |
| 381 | /* Decompression */ |
| 382 | if (!dCompleted) memset(resultBuffer, 0xD6, srcSize); /* warm result buffer */ |
| 383 | |
| 384 | UTIL_sleepMilli(1); /* give processor time to other processes */ |
| 385 | UTIL_waitForNextTick(ticksPerSecond); |
| 386 | UTIL_getTime(&clockStart); |
| 387 | |
| 388 | if (!dCompleted) { |
| 389 | U32 nbLoops = 0; |
inikep | f71828f | 2016-09-22 15:55:01 +0200 | [diff] [blame] | 390 | if (compressor == BMK_ZSTD) { |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 391 | ZSTD_DDict* ddict = ZSTD_createDDict(dictBuffer, dictBufferSize); |
| 392 | if (!ddict) EXM_THROW(2, "ZSTD_createDDict() allocation failure"); |
| 393 | do { |
| 394 | U32 blockNb; |
| 395 | for (blockNb=0; blockNb<nbBlocks; blockNb++) { |
| 396 | size_t const regenSize = ZSTD_decompress_usingDDict(dctx, |
| 397 | blockTable[blockNb].resPtr, blockTable[blockNb].srcSize, |
| 398 | blockTable[blockNb].cPtr, blockTable[blockNb].cSize, |
| 399 | ddict); |
| 400 | if (ZSTD_isError(regenSize)) { |
| 401 | DISPLAY("ZSTD_decompress_usingDDict() failed on block %u : %s \n", |
| 402 | blockNb, ZSTD_getErrorName(regenSize)); |
| 403 | clockLoop = 0; /* force immediate test end */ |
| 404 | break; |
| 405 | } |
| 406 | blockTable[blockNb].resSize = regenSize; |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 407 | } |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 408 | nbLoops++; |
| 409 | } while (UTIL_clockSpanMicro(clockStart, ticksPerSecond) < clockLoop); |
| 410 | ZSTD_freeDDict(ddict); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 411 | } else if (compressor == BMK_ZSTD_STREAM) { |
inikep | f71828f | 2016-09-22 15:55:01 +0200 | [diff] [blame] | 412 | ZSTD_inBuffer inBuffer; |
| 413 | ZSTD_outBuffer outBuffer; |
| 414 | ZSTD_DStream* zbd = ZSTD_createDStream(); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 415 | size_t rSize; |
inikep | f71828f | 2016-09-22 15:55:01 +0200 | [diff] [blame] | 416 | if (zbd == NULL) EXM_THROW(1, "ZSTD_createDStream() allocation failure"); |
inikep | a03b7a7 | 2016-09-26 22:11:55 +0200 | [diff] [blame] | 417 | rSize = ZSTD_initDStream_usingDict(zbd, dictBuffer, dictBufferSize); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 418 | if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_initDStream() failed : %s", ZSTD_getErrorName(rSize)); |
inikep | f71828f | 2016-09-22 15:55:01 +0200 | [diff] [blame] | 419 | do { |
| 420 | U32 blockNb; |
| 421 | for (blockNb=0; blockNb<nbBlocks; blockNb++) { |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 422 | rSize = ZSTD_resetDStream(zbd); |
| 423 | if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_resetDStream() failed : %s", ZSTD_getErrorName(rSize)); |
inikep | f71828f | 2016-09-22 15:55:01 +0200 | [diff] [blame] | 424 | inBuffer.src = blockTable[blockNb].cPtr; |
| 425 | inBuffer.size = blockTable[blockNb].cSize; |
| 426 | inBuffer.pos = 0; |
| 427 | outBuffer.dst = blockTable[blockNb].resPtr; |
| 428 | outBuffer.size = blockTable[blockNb].srcSize; |
| 429 | outBuffer.pos = 0; |
| 430 | rSize = ZSTD_decompressStream(zbd, &outBuffer, &inBuffer); |
| 431 | if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_decompressStream() failed : %s", ZSTD_getErrorName(rSize)); |
| 432 | blockTable[blockNb].resSize = outBuffer.pos; |
| 433 | } |
| 434 | nbLoops++; |
| 435 | } while (UTIL_clockSpanMicro(clockStart, ticksPerSecond) < clockLoop); |
| 436 | ZSTD_freeDStream(zbd); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 437 | } else if (compressor == BMK_ZWRAP_ZLIB_REUSE || compressor == BMK_ZWRAP_ZSTD_REUSE || compressor == BMK_ZLIB_REUSE) { |
| 438 | z_stream inf; |
| 439 | int ret; |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 440 | if (compressor == BMK_ZLIB_REUSE) ZWRAP_setDecompressionType(ZWRAP_FORCE_ZLIB); |
| 441 | else ZWRAP_setDecompressionType(ZWRAP_AUTO); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 442 | inf.zalloc = Z_NULL; |
| 443 | inf.zfree = Z_NULL; |
| 444 | inf.opaque = Z_NULL; |
| 445 | ret = inflateInit(&inf); |
| 446 | if (ret != Z_OK) EXM_THROW(1, "inflateInit failure"); |
| 447 | do { |
| 448 | U32 blockNb; |
| 449 | for (blockNb=0; blockNb<nbBlocks; blockNb++) { |
inikep | 706876f | 2016-09-27 16:56:07 +0200 | [diff] [blame] | 450 | if (ZWRAP_isUsingZSTDdecompression(&inf)) |
inikep | 20859af | 2016-09-27 17:27:43 +0200 | [diff] [blame] | 451 | ret = ZWRAP_inflateReset_keepDict(&inf); /* reuse dictionary to make decompression faster; inflate will return Z_NEED_DICT only for the first time */ |
inikep | 706876f | 2016-09-27 16:56:07 +0200 | [diff] [blame] | 452 | else |
| 453 | ret = inflateReset(&inf); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 454 | if (ret != Z_OK) EXM_THROW(1, "inflateReset failure"); |
Przemyslaw Skibinski | 6cecb35 | 2016-11-04 17:49:17 +0100 | [diff] [blame] | 455 | inf.next_in = (z_const void*) blockTable[blockNb].cPtr; |
Yann Collet | 9ceb49e | 2016-12-22 15:26:33 +0100 | [diff] [blame] | 456 | inf.avail_in = (uInt)blockTable[blockNb].cSize; |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 457 | inf.total_in = 0; |
| 458 | inf.next_out = (void*) blockTable[blockNb].resPtr; |
Yann Collet | 9ceb49e | 2016-12-22 15:26:33 +0100 | [diff] [blame] | 459 | inf.avail_out = (uInt)blockTable[blockNb].srcSize; |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 460 | inf.total_out = 0; |
| 461 | ret = inflate(&inf, Z_FINISH); |
inikep | a03b7a7 | 2016-09-26 22:11:55 +0200 | [diff] [blame] | 462 | if (ret == Z_NEED_DICT) { |
| 463 | ret = inflateSetDictionary(&inf, dictBuffer, dictBufferSize); |
| 464 | if (ret != Z_OK) EXM_THROW(1, "inflateSetDictionary failure"); |
| 465 | ret = inflate(&inf, Z_FINISH); |
| 466 | } |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 467 | if (ret != Z_STREAM_END) EXM_THROW(1, "inflate failure"); |
| 468 | blockTable[blockNb].resSize = inf.total_out; |
| 469 | } |
| 470 | nbLoops++; |
| 471 | } while (UTIL_clockSpanMicro(clockStart, ticksPerSecond) < clockLoop); |
| 472 | ret = inflateEnd(&inf); |
| 473 | if (ret != Z_OK) EXM_THROW(1, "inflateEnd failure"); |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 474 | } else { |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 475 | z_stream inf; |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 476 | if (compressor == BMK_ZLIB) ZWRAP_setDecompressionType(ZWRAP_FORCE_ZLIB); |
| 477 | else ZWRAP_setDecompressionType(ZWRAP_AUTO); |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 478 | do { |
| 479 | U32 blockNb; |
| 480 | for (blockNb=0; blockNb<nbBlocks; blockNb++) { |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 481 | int ret; |
| 482 | inf.zalloc = Z_NULL; |
| 483 | inf.zfree = Z_NULL; |
| 484 | inf.opaque = Z_NULL; |
| 485 | ret = inflateInit(&inf); |
| 486 | if (ret != Z_OK) EXM_THROW(1, "inflateInit failure"); |
Przemyslaw Skibinski | 6cecb35 | 2016-11-04 17:49:17 +0100 | [diff] [blame] | 487 | inf.next_in = (z_const void*) blockTable[blockNb].cPtr; |
Yann Collet | 9ceb49e | 2016-12-22 15:26:33 +0100 | [diff] [blame] | 488 | inf.avail_in = (uInt)blockTable[blockNb].cSize; |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 489 | inf.total_in = 0; |
| 490 | inf.next_out = (void*) blockTable[blockNb].resPtr; |
Yann Collet | 9ceb49e | 2016-12-22 15:26:33 +0100 | [diff] [blame] | 491 | inf.avail_out = (uInt)blockTable[blockNb].srcSize; |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 492 | inf.total_out = 0; |
| 493 | ret = inflate(&inf, Z_FINISH); |
inikep | a03b7a7 | 2016-09-26 22:11:55 +0200 | [diff] [blame] | 494 | if (ret == Z_NEED_DICT) { |
| 495 | ret = inflateSetDictionary(&inf, dictBuffer, dictBufferSize); |
| 496 | if (ret != Z_OK) EXM_THROW(1, "inflateSetDictionary failure"); |
| 497 | ret = inflate(&inf, Z_FINISH); |
| 498 | } |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 499 | if (ret != Z_STREAM_END) EXM_THROW(1, "inflate failure"); |
| 500 | ret = inflateEnd(&inf); |
| 501 | if (ret != Z_OK) EXM_THROW(1, "inflateEnd failure"); |
| 502 | blockTable[blockNb].resSize = inf.total_out; |
| 503 | } |
| 504 | nbLoops++; |
| 505 | } while (UTIL_clockSpanMicro(clockStart, ticksPerSecond) < clockLoop); |
| 506 | } |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 507 | { U64 const clockSpan = UTIL_clockSpanMicro(clockStart, ticksPerSecond); |
| 508 | if (clockSpan < fastestD*nbLoops) fastestD = clockSpan / nbLoops; |
| 509 | totalDTime += clockSpan; |
| 510 | dCompleted = totalDTime>maxTime; |
| 511 | } } |
| 512 | |
| 513 | markNb = (markNb+1) % NB_MARKS; |
| 514 | DISPLAYLEVEL(2, "%2s-%-17.17s :%10u ->%10u (%5.3f),%6.1f MB/s ,%6.1f MB/s\r", |
| 515 | marks[markNb], displayName, (U32)srcSize, (U32)cSize, ratio, |
| 516 | (double)srcSize / fastestC, |
| 517 | (double)srcSize / fastestD ); |
| 518 | |
| 519 | /* CRC Checking */ |
| 520 | { U64 const crcCheck = XXH64(resultBuffer, srcSize, 0); |
| 521 | if (crcOrig!=crcCheck) { |
| 522 | size_t u; |
| 523 | DISPLAY("!!! WARNING !!! %14s : Invalid Checksum : %x != %x \n", displayName, (unsigned)crcOrig, (unsigned)crcCheck); |
| 524 | for (u=0; u<srcSize; u++) { |
| 525 | if (((const BYTE*)srcBuffer)[u] != ((const BYTE*)resultBuffer)[u]) { |
| 526 | U32 segNb, bNb, pos; |
| 527 | size_t bacc = 0; |
| 528 | DISPLAY("Decoding error at pos %u ", (U32)u); |
| 529 | for (segNb = 0; segNb < nbBlocks; segNb++) { |
| 530 | if (bacc + blockTable[segNb].srcSize > u) break; |
| 531 | bacc += blockTable[segNb].srcSize; |
| 532 | } |
| 533 | pos = (U32)(u - bacc); |
| 534 | bNb = pos / (128 KB); |
| 535 | DISPLAY("(block %u, sub %u, pos %u) \n", segNb, bNb, pos); |
| 536 | break; |
| 537 | } |
| 538 | if (u==srcSize-1) { /* should never happen */ |
| 539 | DISPLAY("no difference detected\n"); |
| 540 | } } |
| 541 | break; |
| 542 | } } /* CRC Checking */ |
| 543 | #endif |
| 544 | } /* for (testNb = 1; testNb <= (g_nbIterations + !g_nbIterations); testNb++) */ |
| 545 | |
| 546 | if (g_displayLevel == 1) { |
| 547 | double cSpeed = (double)srcSize / fastestC; |
| 548 | double dSpeed = (double)srcSize / fastestD; |
| 549 | if (g_additionalParam) |
| 550 | DISPLAY("-%-3i%11i (%5.3f) %6.2f MB/s %6.1f MB/s %s (param=%d)\n", cLevel, (int)cSize, ratio, cSpeed, dSpeed, displayName, g_additionalParam); |
| 551 | else |
| 552 | DISPLAY("-%-3i%11i (%5.3f) %6.2f MB/s %6.1f MB/s %s\n", cLevel, (int)cSize, ratio, cSpeed, dSpeed, displayName); |
| 553 | } |
| 554 | DISPLAYLEVEL(2, "%2i#\n", cLevel); |
| 555 | } /* Bench */ |
| 556 | |
| 557 | /* clean up */ |
| 558 | free(blockTable); |
| 559 | free(compressedBuffer); |
| 560 | free(resultBuffer); |
| 561 | ZSTD_freeCCtx(ctx); |
| 562 | ZSTD_freeDCtx(dctx); |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | |
| 567 | static size_t BMK_findMaxMem(U64 requiredMem) |
| 568 | { |
| 569 | size_t const step = 64 MB; |
| 570 | BYTE* testmem = NULL; |
| 571 | |
| 572 | requiredMem = (((requiredMem >> 26) + 1) << 26); |
| 573 | requiredMem += step; |
| 574 | if (requiredMem > maxMemory) requiredMem = maxMemory; |
| 575 | |
| 576 | do { |
| 577 | testmem = (BYTE*)malloc((size_t)requiredMem); |
| 578 | requiredMem -= step; |
| 579 | } while (!testmem); |
| 580 | |
| 581 | free(testmem); |
| 582 | return (size_t)(requiredMem); |
| 583 | } |
| 584 | |
| 585 | static void BMK_benchCLevel(void* srcBuffer, size_t benchedSize, |
| 586 | const char* displayName, int cLevel, int cLevelLast, |
| 587 | const size_t* fileSizes, unsigned nbFiles, |
| 588 | const void* dictBuffer, size_t dictBufferSize) |
| 589 | { |
| 590 | int l; |
| 591 | |
| 592 | const char* pch = strrchr(displayName, '\\'); /* Windows */ |
| 593 | if (!pch) pch = strrchr(displayName, '/'); /* Linux */ |
| 594 | if (pch) displayName = pch+1; |
| 595 | |
Przemyslaw Skibinski | 94abd6a | 2017-02-07 16:36:19 +0100 | [diff] [blame] | 596 | SET_REALTIME_PRIORITY; |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 597 | |
| 598 | if (g_displayLevel == 1 && !g_additionalParam) |
inikep | 68cd476 | 2016-09-23 12:42:21 +0200 | [diff] [blame] | 599 | DISPLAY("bench %s %s: input %u bytes, %u seconds, %u KB blocks\n", ZSTD_VERSION_STRING, ZSTD_GIT_COMMIT_STRING, (U32)benchedSize, g_nbIterations, (U32)(g_blockSize>>10)); |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 600 | |
| 601 | if (cLevelLast < cLevel) cLevelLast = cLevel; |
| 602 | |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 603 | DISPLAY("benchmarking zstd %s (using ZSTD_CStream)\n", ZSTD_VERSION_STRING); |
inikep | 8e8b046 | 2016-09-22 14:42:32 +0200 | [diff] [blame] | 604 | for (l=cLevel; l <= cLevelLast; l++) { |
| 605 | BMK_benchMem(srcBuffer, benchedSize, |
| 606 | displayName, l, |
| 607 | fileSizes, nbFiles, |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 608 | dictBuffer, dictBufferSize, BMK_ZSTD_STREAM); |
inikep | 8e8b046 | 2016-09-22 14:42:32 +0200 | [diff] [blame] | 609 | } |
| 610 | |
Przemyslaw Skibinski | 96fca2b | 2016-11-25 14:36:27 +0100 | [diff] [blame] | 611 | DISPLAY("benchmarking zstd %s (using ZSTD_CCtx)\n", ZSTD_VERSION_STRING); |
| 612 | for (l=cLevel; l <= cLevelLast; l++) { |
| 613 | BMK_benchMem(srcBuffer, benchedSize, |
| 614 | displayName, l, |
| 615 | fileSizes, nbFiles, |
| 616 | dictBuffer, dictBufferSize, BMK_ZSTD); |
| 617 | } |
| 618 | |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 619 | DISPLAY("benchmarking zstd %s (using zlibWrapper)\n", ZSTD_VERSION_STRING); |
inikep | 8e8b046 | 2016-09-22 14:42:32 +0200 | [diff] [blame] | 620 | for (l=cLevel; l <= cLevelLast; l++) { |
| 621 | BMK_benchMem(srcBuffer, benchedSize, |
| 622 | displayName, l, |
| 623 | fileSizes, nbFiles, |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 624 | dictBuffer, dictBufferSize, BMK_ZWRAP_ZSTD_REUSE); |
inikep | 8e8b046 | 2016-09-22 14:42:32 +0200 | [diff] [blame] | 625 | } |
| 626 | |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 627 | DISPLAY("benchmarking zstd %s (zlibWrapper not reusing a context)\n", ZSTD_VERSION_STRING); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 628 | for (l=cLevel; l <= cLevelLast; l++) { |
| 629 | BMK_benchMem(srcBuffer, benchedSize, |
| 630 | displayName, l, |
| 631 | fileSizes, nbFiles, |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 632 | dictBuffer, dictBufferSize, BMK_ZWRAP_ZSTD); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 633 | } |
| 634 | |
inikep | 8e8b046 | 2016-09-22 14:42:32 +0200 | [diff] [blame] | 635 | |
| 636 | if (cLevelLast > Z_BEST_COMPRESSION) cLevelLast = Z_BEST_COMPRESSION; |
| 637 | |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 638 | DISPLAY("\n"); |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 639 | DISPLAY("benchmarking zlib %s\n", ZLIB_VERSION); |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 640 | for (l=cLevel; l <= cLevelLast; l++) { |
| 641 | BMK_benchMem(srcBuffer, benchedSize, |
| 642 | displayName, l, |
| 643 | fileSizes, nbFiles, |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 644 | dictBuffer, dictBufferSize, BMK_ZLIB_REUSE); |
| 645 | } |
| 646 | |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 647 | DISPLAY("benchmarking zlib %s (zlib not reusing a context)\n", ZLIB_VERSION); |
| 648 | for (l=cLevel; l <= cLevelLast; l++) { |
| 649 | BMK_benchMem(srcBuffer, benchedSize, |
| 650 | displayName, l, |
| 651 | fileSizes, nbFiles, |
| 652 | dictBuffer, dictBufferSize, BMK_ZLIB); |
| 653 | } |
| 654 | |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 655 | DISPLAY("benchmarking zlib %s (using zlibWrapper)\n", ZLIB_VERSION); |
inikep | 54320ce | 2016-09-22 11:52:53 +0200 | [diff] [blame] | 656 | for (l=cLevel; l <= cLevelLast; l++) { |
| 657 | BMK_benchMem(srcBuffer, benchedSize, |
| 658 | displayName, l, |
| 659 | fileSizes, nbFiles, |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 660 | dictBuffer, dictBufferSize, BMK_ZWRAP_ZLIB_REUSE); |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 661 | } |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 662 | |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 663 | DISPLAY("benchmarking zlib %s (zlibWrapper not reusing a context)\n", ZLIB_VERSION); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 664 | for (l=cLevel; l <= cLevelLast; l++) { |
| 665 | BMK_benchMem(srcBuffer, benchedSize, |
| 666 | displayName, l, |
| 667 | fileSizes, nbFiles, |
inikep | 252c20d | 2016-09-23 09:08:40 +0200 | [diff] [blame] | 668 | dictBuffer, dictBufferSize, BMK_ZWRAP_ZLIB); |
inikep | f7ab3ad | 2016-09-22 17:59:10 +0200 | [diff] [blame] | 669 | } |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | |
| 673 | /*! BMK_loadFiles() : |
| 674 | Loads `buffer` with content of files listed within `fileNamesTable`. |
| 675 | At most, fills `buffer` entirely */ |
| 676 | static void BMK_loadFiles(void* buffer, size_t bufferSize, |
| 677 | size_t* fileSizes, |
| 678 | const char** fileNamesTable, unsigned nbFiles) |
| 679 | { |
| 680 | size_t pos = 0, totalSize = 0; |
| 681 | unsigned n; |
| 682 | for (n=0; n<nbFiles; n++) { |
| 683 | FILE* f; |
| 684 | U64 fileSize = UTIL_getFileSize(fileNamesTable[n]); |
| 685 | if (UTIL_isDirectory(fileNamesTable[n])) { |
| 686 | DISPLAYLEVEL(2, "Ignoring %s directory... \n", fileNamesTable[n]); |
| 687 | fileSizes[n] = 0; |
| 688 | continue; |
| 689 | } |
| 690 | f = fopen(fileNamesTable[n], "rb"); |
| 691 | if (f==NULL) EXM_THROW(10, "impossible to open file %s", fileNamesTable[n]); |
| 692 | DISPLAYUPDATE(2, "Loading %s... \r", fileNamesTable[n]); |
| 693 | if (fileSize > bufferSize-pos) fileSize = bufferSize-pos, nbFiles=n; /* buffer too small - stop after this file */ |
| 694 | { size_t const readSize = fread(((char*)buffer)+pos, 1, (size_t)fileSize, f); |
| 695 | if (readSize != (size_t)fileSize) EXM_THROW(11, "could not read %s", fileNamesTable[n]); |
| 696 | pos += readSize; } |
| 697 | fileSizes[n] = (size_t)fileSize; |
| 698 | totalSize += (size_t)fileSize; |
| 699 | fclose(f); |
| 700 | } |
| 701 | |
| 702 | if (totalSize == 0) EXM_THROW(12, "no data to bench"); |
| 703 | } |
| 704 | |
| 705 | static void BMK_benchFileTable(const char** fileNamesTable, unsigned nbFiles, |
| 706 | const char* dictFileName, int cLevel, int cLevelLast) |
| 707 | { |
| 708 | void* srcBuffer; |
| 709 | size_t benchedSize; |
| 710 | void* dictBuffer = NULL; |
| 711 | size_t dictBufferSize = 0; |
| 712 | size_t* fileSizes = (size_t*)malloc(nbFiles * sizeof(size_t)); |
| 713 | U64 const totalSizeToLoad = UTIL_getTotalFileSize(fileNamesTable, nbFiles); |
| 714 | char mfName[20] = {0}; |
| 715 | |
| 716 | if (!fileSizes) EXM_THROW(12, "not enough memory for fileSizes"); |
| 717 | |
| 718 | /* Load dictionary */ |
| 719 | if (dictFileName != NULL) { |
| 720 | U64 dictFileSize = UTIL_getFileSize(dictFileName); |
| 721 | if (dictFileSize > 64 MB) EXM_THROW(10, "dictionary file %s too large", dictFileName); |
| 722 | dictBufferSize = (size_t)dictFileSize; |
| 723 | dictBuffer = malloc(dictBufferSize); |
| 724 | if (dictBuffer==NULL) EXM_THROW(11, "not enough memory for dictionary (%u bytes)", (U32)dictBufferSize); |
| 725 | BMK_loadFiles(dictBuffer, dictBufferSize, fileSizes, &dictFileName, 1); |
| 726 | } |
| 727 | |
| 728 | /* Memory allocation & restrictions */ |
| 729 | benchedSize = BMK_findMaxMem(totalSizeToLoad * 3) / 3; |
| 730 | if ((U64)benchedSize > totalSizeToLoad) benchedSize = (size_t)totalSizeToLoad; |
| 731 | if (benchedSize < totalSizeToLoad) |
| 732 | DISPLAY("Not enough memory; testing %u MB only...\n", (U32)(benchedSize >> 20)); |
| 733 | srcBuffer = malloc(benchedSize); |
| 734 | if (!srcBuffer) EXM_THROW(12, "not enough memory"); |
| 735 | |
| 736 | /* Load input buffer */ |
| 737 | BMK_loadFiles(srcBuffer, benchedSize, fileSizes, fileNamesTable, nbFiles); |
| 738 | |
| 739 | /* Bench */ |
| 740 | snprintf (mfName, sizeof(mfName), " %u files", nbFiles); |
| 741 | { const char* displayName = (nbFiles > 1) ? mfName : fileNamesTable[0]; |
| 742 | BMK_benchCLevel(srcBuffer, benchedSize, |
| 743 | displayName, cLevel, cLevelLast, |
| 744 | fileSizes, nbFiles, |
| 745 | dictBuffer, dictBufferSize); |
| 746 | } |
| 747 | |
| 748 | /* clean up */ |
| 749 | free(srcBuffer); |
| 750 | free(dictBuffer); |
| 751 | free(fileSizes); |
| 752 | } |
| 753 | |
| 754 | |
| 755 | static void BMK_syntheticTest(int cLevel, int cLevelLast, double compressibility) |
| 756 | { |
| 757 | char name[20] = {0}; |
| 758 | size_t benchedSize = 10000000; |
| 759 | void* const srcBuffer = malloc(benchedSize); |
| 760 | |
| 761 | /* Memory allocation */ |
| 762 | if (!srcBuffer) EXM_THROW(21, "not enough memory"); |
| 763 | |
| 764 | /* Fill input buffer */ |
| 765 | RDG_genBuffer(srcBuffer, benchedSize, compressibility, 0.0, 0); |
| 766 | |
| 767 | /* Bench */ |
| 768 | snprintf (name, sizeof(name), "Synthetic %2u%%", (unsigned)(compressibility*100)); |
| 769 | BMK_benchCLevel(srcBuffer, benchedSize, name, cLevel, cLevelLast, &benchedSize, 1, NULL, 0); |
| 770 | |
| 771 | /* clean up */ |
| 772 | free(srcBuffer); |
| 773 | } |
| 774 | |
| 775 | |
| 776 | int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles, |
| 777 | const char* dictFileName, int cLevel, int cLevelLast) |
| 778 | { |
| 779 | double const compressibility = (double)g_compressibilityDefault / 100; |
| 780 | |
| 781 | if (nbFiles == 0) |
| 782 | BMK_syntheticTest(cLevel, cLevelLast, compressibility); |
| 783 | else |
| 784 | BMK_benchFileTable(fileNamesTable, nbFiles, dictFileName, cLevel, cLevelLast); |
| 785 | return 0; |
| 786 | } |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | /*-************************************ |
| 792 | * Command Line |
| 793 | **************************************/ |
| 794 | static int usage(const char* programName) |
| 795 | { |
| 796 | DISPLAY(WELCOME_MESSAGE); |
| 797 | DISPLAY( "Usage :\n"); |
| 798 | DISPLAY( " %s [args] [FILE(s)] [-o file]\n", programName); |
| 799 | DISPLAY( "\n"); |
| 800 | DISPLAY( "FILE : a filename\n"); |
| 801 | DISPLAY( " with no FILE, or when FILE is - , read standard input\n"); |
| 802 | DISPLAY( "Arguments :\n"); |
| 803 | DISPLAY( " -D file: use `file` as Dictionary \n"); |
| 804 | DISPLAY( " -h/-H : display help/long help and exit\n"); |
| 805 | DISPLAY( " -V : display Version number and exit\n"); |
| 806 | DISPLAY( " -v : verbose mode; specify multiple times to increase log level (default:%d)\n", DEFAULT_DISPLAY_LEVEL); |
| 807 | DISPLAY( " -q : suppress warnings; specify twice to suppress errors too\n"); |
| 808 | #ifdef UTIL_HAS_CREATEFILELIST |
| 809 | DISPLAY( " -r : operate recursively on directories\n"); |
| 810 | #endif |
| 811 | DISPLAY( "\n"); |
| 812 | DISPLAY( "Benchmark arguments :\n"); |
inikep | 8e8b046 | 2016-09-22 14:42:32 +0200 | [diff] [blame] | 813 | DISPLAY( " -b# : benchmark file(s), using # compression level (default : %d) \n", ZSTDCLI_CLEVEL_DEFAULT); |
| 814 | DISPLAY( " -e# : test all compression levels from -bX to # (default: %d)\n", ZSTDCLI_CLEVEL_DEFAULT); |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 815 | DISPLAY( " -i# : minimum evaluation time in seconds (default : 3s)\n"); |
| 816 | DISPLAY( " -B# : cut file into independent blocks of size # (default: no block)\n"); |
| 817 | return 0; |
| 818 | } |
| 819 | |
| 820 | static int badusage(const char* programName) |
| 821 | { |
| 822 | DISPLAYLEVEL(1, "Incorrect parameters\n"); |
| 823 | if (g_displayLevel >= 1) usage(programName); |
| 824 | return 1; |
| 825 | } |
| 826 | |
| 827 | static void waitEnter(void) |
| 828 | { |
| 829 | int unused; |
| 830 | DISPLAY("Press enter to continue...\n"); |
| 831 | unused = getchar(); |
| 832 | (void)unused; |
| 833 | } |
| 834 | |
| 835 | /*! readU32FromChar() : |
| 836 | @return : unsigned integer value reach from input in `char` format |
| 837 | Will also modify `*stringPtr`, advancing it to position where it stopped reading. |
| 838 | Note : this function can overflow if digit string > MAX_UINT */ |
| 839 | static unsigned readU32FromChar(const char** stringPtr) |
| 840 | { |
| 841 | unsigned result = 0; |
| 842 | while ((**stringPtr >='0') && (**stringPtr <='9')) |
| 843 | result *= 10, result += **stringPtr - '0', (*stringPtr)++ ; |
| 844 | return result; |
| 845 | } |
| 846 | |
| 847 | |
| 848 | #define CLEAN_RETURN(i) { operationResult = (i); goto _end; } |
| 849 | |
| 850 | int main(int argCount, char** argv) |
| 851 | { |
| 852 | int argNb, |
| 853 | main_pause=0, |
| 854 | nextEntryIsDictionary=0, |
| 855 | operationResult=0, |
| 856 | nextArgumentIsFile=0; |
| 857 | int cLevel = ZSTDCLI_CLEVEL_DEFAULT; |
| 858 | int cLevelLast = 1; |
| 859 | unsigned recursive = 0; |
| 860 | const char** filenameTable = (const char**)malloc(argCount * sizeof(const char*)); /* argCount >= 1 */ |
| 861 | unsigned filenameIdx = 0; |
| 862 | const char* programName = argv[0]; |
| 863 | const char* dictFileName = NULL; |
| 864 | char* dynNameSpace = NULL; |
| 865 | #ifdef UTIL_HAS_CREATEFILELIST |
| 866 | const char** fileNamesTable = NULL; |
| 867 | char* fileNamesBuf = NULL; |
| 868 | unsigned fileNamesNb; |
| 869 | #endif |
| 870 | |
| 871 | /* init */ |
| 872 | if (filenameTable==NULL) { DISPLAY("zstd: %s \n", strerror(errno)); exit(1); } |
| 873 | displayOut = stderr; |
| 874 | |
| 875 | /* Pick out program name from path. Don't rely on stdlib because of conflicting behavior */ |
| 876 | { size_t pos; |
| 877 | for (pos = (int)strlen(programName); pos > 0; pos--) { if (programName[pos] == '/') { pos++; break; } } |
| 878 | programName += pos; |
| 879 | } |
| 880 | |
| 881 | /* command switches */ |
| 882 | for(argNb=1; argNb<argCount; argNb++) { |
| 883 | const char* argument = argv[argNb]; |
| 884 | if(!argument) continue; /* Protection if argument empty */ |
| 885 | |
| 886 | if (nextArgumentIsFile==0) { |
| 887 | |
| 888 | /* long commands (--long-word) */ |
| 889 | if (!strcmp(argument, "--")) { nextArgumentIsFile=1; continue; } |
| 890 | if (!strcmp(argument, "--version")) { displayOut=stdout; DISPLAY(WELCOME_MESSAGE); CLEAN_RETURN(0); } |
| 891 | if (!strcmp(argument, "--help")) { displayOut=stdout; CLEAN_RETURN(usage(programName)); } |
| 892 | if (!strcmp(argument, "--verbose")) { g_displayLevel++; continue; } |
| 893 | if (!strcmp(argument, "--quiet")) { g_displayLevel--; continue; } |
| 894 | |
| 895 | /* Decode commands (note : aggregated commands are allowed) */ |
| 896 | if (argument[0]=='-') { |
| 897 | argument++; |
| 898 | |
| 899 | while (argument[0]!=0) { |
| 900 | switch(argument[0]) |
| 901 | { |
| 902 | /* Display help */ |
| 903 | case 'V': displayOut=stdout; DISPLAY(WELCOME_MESSAGE); CLEAN_RETURN(0); /* Version Only */ |
| 904 | case 'H': |
| 905 | case 'h': displayOut=stdout; CLEAN_RETURN(usage(programName)); |
| 906 | |
| 907 | /* Use file content as dictionary */ |
| 908 | case 'D': nextEntryIsDictionary = 1; argument++; break; |
| 909 | |
| 910 | /* Verbose mode */ |
| 911 | case 'v': g_displayLevel++; argument++; break; |
| 912 | |
| 913 | /* Quiet mode */ |
| 914 | case 'q': g_displayLevel--; argument++; break; |
| 915 | |
| 916 | #ifdef UTIL_HAS_CREATEFILELIST |
| 917 | /* recursive */ |
| 918 | case 'r': recursive=1; argument++; break; |
| 919 | #endif |
| 920 | |
| 921 | /* Benchmark */ |
| 922 | case 'b': |
| 923 | /* first compression Level */ |
| 924 | argument++; |
| 925 | cLevel = readU32FromChar(&argument); |
| 926 | break; |
| 927 | |
| 928 | /* range bench (benchmark only) */ |
| 929 | case 'e': |
| 930 | /* last compression Level */ |
| 931 | argument++; |
| 932 | cLevelLast = readU32FromChar(&argument); |
| 933 | break; |
| 934 | |
| 935 | /* Modify Nb Iterations (benchmark only) */ |
| 936 | case 'i': |
| 937 | argument++; |
| 938 | { U32 const iters = readU32FromChar(&argument); |
| 939 | BMK_setNotificationLevel(g_displayLevel); |
| 940 | BMK_SetNbIterations(iters); |
| 941 | } |
| 942 | break; |
| 943 | |
| 944 | /* cut input into blocks (benchmark only) */ |
| 945 | case 'B': |
| 946 | argument++; |
| 947 | { size_t bSize = readU32FromChar(&argument); |
| 948 | if (toupper(*argument)=='K') bSize<<=10, argument++; /* allows using KB notation */ |
| 949 | if (toupper(*argument)=='M') bSize<<=20, argument++; |
| 950 | if (toupper(*argument)=='B') argument++; |
| 951 | BMK_setNotificationLevel(g_displayLevel); |
| 952 | BMK_SetBlockSize(bSize); |
| 953 | } |
| 954 | break; |
| 955 | |
| 956 | /* Pause at the end (-p) or set an additional param (-p#) (hidden option) */ |
| 957 | case 'p': argument++; |
| 958 | if ((*argument>='0') && (*argument<='9')) { |
| 959 | BMK_setAdditionalParam(readU32FromChar(&argument)); |
| 960 | } else |
| 961 | main_pause=1; |
| 962 | break; |
| 963 | /* unknown command */ |
| 964 | default : CLEAN_RETURN(badusage(programName)); |
| 965 | } |
| 966 | } |
| 967 | continue; |
| 968 | } /* if (argument[0]=='-') */ |
| 969 | |
| 970 | } /* if (nextArgumentIsAFile==0) */ |
| 971 | |
| 972 | if (nextEntryIsDictionary) { |
| 973 | nextEntryIsDictionary = 0; |
| 974 | dictFileName = argument; |
| 975 | continue; |
| 976 | } |
| 977 | |
| 978 | /* add filename to list */ |
| 979 | filenameTable[filenameIdx++] = argument; |
| 980 | } |
| 981 | |
| 982 | /* Welcome message (if verbose) */ |
| 983 | DISPLAYLEVEL(3, WELCOME_MESSAGE); |
| 984 | |
| 985 | #ifdef UTIL_HAS_CREATEFILELIST |
| 986 | if (recursive) { |
Sean Purcell | 680e4e0 | 2017-03-23 11:52:09 -0700 | [diff] [blame] | 987 | fileNamesTable = UTIL_createFileList(filenameTable, filenameIdx, &fileNamesBuf, &fileNamesNb, 1); |
inikep | dfef5dd | 2016-09-22 10:23:26 +0200 | [diff] [blame] | 988 | if (fileNamesTable) { |
| 989 | unsigned u; |
| 990 | for (u=0; u<fileNamesNb; u++) DISPLAYLEVEL(4, "%u %s\n", u, fileNamesTable[u]); |
| 991 | free((void*)filenameTable); |
| 992 | filenameTable = fileNamesTable; |
| 993 | filenameIdx = fileNamesNb; |
| 994 | } |
| 995 | } |
| 996 | #endif |
| 997 | |
| 998 | BMK_setNotificationLevel(g_displayLevel); |
| 999 | BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel, cLevelLast); |
| 1000 | |
| 1001 | _end: |
| 1002 | if (main_pause) waitEnter(); |
| 1003 | free(dynNameSpace); |
| 1004 | #ifdef UTIL_HAS_CREATEFILELIST |
| 1005 | if (fileNamesTable) |
| 1006 | UTIL_freeFileList(fileNamesTable, fileNamesBuf); |
| 1007 | else |
| 1008 | #endif |
| 1009 | free((void*)filenameTable); |
| 1010 | return operationResult; |
| 1011 | } |