]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
benchmark uses ZSTD_duplicateCCtx()
authorYann Collet <yann.collet.73@gmail.com>
Thu, 14 Jan 2016 18:13:22 +0000 (19:13 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Thu, 14 Jan 2016 18:13:22 +0000 (19:13 +0100)
programs/bench.c

index b80d6990becf44aaa1e5e1625642caf5a3729522..3c74a572ca410e2e90f470b9c9e1d71ff10fc213 100644 (file)
@@ -224,6 +224,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
     const size_t maxCompressedSize = ZSTD_compressBound(srcSize) + (maxNbBlocks * 1024);   /* add some room for safety */
     void* const compressedBuffer = malloc(maxCompressedSize);
     void* const resultBuffer = malloc(srcSize);
+    ZSTD_CCtx* refCtx = ZSTD_createCCtx();
     ZSTD_CCtx* ctx = ZSTD_createCCtx();
     ZSTD_DCtx* dctx = ZSTD_createDCtx();
     U64 crcOrig = XXH64(srcBuffer, srcSize, 0);
@@ -233,7 +234,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
     if (strlen(displayName)>17) displayName += strlen(displayName)-17;   /* can only display 17 characters */
 
     /* Memory allocation & restrictions */
-    if (!compressedBuffer || !resultBuffer || !blockTable || !ctx || !dctx)
+    if (!compressedBuffer || !resultBuffer || !blockTable || !refCtx || !ctx || !dctx)
         EXM_THROW(31, "not enough memory");
 
     /* Init blockTable data */
@@ -291,12 +292,27 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
             milliTime = BMK_GetMilliStart();
             while (BMK_GetMilliSpan(milliTime) < TIMELOOP)
             {
+                ZSTD_compressBegin_advanced(refCtx, ZSTD_getParams(cLevel, dictBufferSize+blockSize));
+                ZSTD_compress_insertDictionary(refCtx, dictBuffer, dictBufferSize);
                 for (blockNb=0; blockNb<nbBlocks; blockNb++)
-                    blockTable[blockNb].cSize = ZSTD_compress_usingDict(ctx,
+                {
+                    ZSTD_duplicateCCtx(ctx, refCtx);
+                    size_t rSize = ZSTD_compressContinue(ctx,
+                                          blockTable[blockNb].cPtr,  blockTable[blockNb].cRoom,
+                                          blockTable[blockNb].srcPtr,blockTable[blockNb].srcSize);
+                    if (ZSTD_isError(rSize)) EXM_THROW(1, "ZSTD_compressContinue() failed : %s", ZSTD_getErrorName(rSize));
+                    blockTable[blockNb].cSize = rSize;
+                    rSize = ZSTD_compressEnd(ctx,
+                                          blockTable[blockNb].cPtr  + rSize,
+                                          blockTable[blockNb].cRoom - rSize);
+                    if (ZSTD_isError(rSize)) EXM_THROW(2, "ZSTD_compressEnd() failed : %s", ZSTD_getErrorName(rSize));
+                    blockTable[blockNb].cSize += rSize;
+                }
+                    /*blockTable[blockNb].cSize = ZSTD_compress_usingDict(ctx,
                                                               blockTable[blockNb].cPtr,  blockTable[blockNb].cRoom,
                                                               blockTable[blockNb].srcPtr,blockTable[blockNb].srcSize,
                                                               dictBuffer, dictBufferSize,
-                                                              cLevel);
+                                                              cLevel);*/
                 nbLoops++;
             }
             milliTime = BMK_GetMilliSpan(milliTime);
@@ -358,6 +374,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
     /* clean up */
     free(compressedBuffer);
     free(resultBuffer);
+    ZSTD_freeCCtx(refCtx);
     ZSTD_freeCCtx(ctx);
     ZSTD_freeDCtx(dctx);
     return 0;