]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fix benchmark issue when measuring only decoding speed 1033/head
authorYann Collet <cyan@fb.com>
Mon, 5 Mar 2018 21:50:07 +0000 (13:50 -0800)
committerYann Collet <cyan@fb.com>
Mon, 5 Mar 2018 21:57:41 +0000 (13:57 -0800)
zstd bench module can focus on decompression speed _only_.
This is useful when trying to measure performance
on large input data compressed using a high level
as compression time becomes problematic (too long).

This mode is triggered by command : zstd -b -d

Problem was : in such a mode,
measured decoding speed was > 10% slower
than in nominal mode (compression + decompression),
making decompression benchmark mode much less useful.

This patch fixes the issue.
It's not completely clear why, but
moving the `memcpy()` operation sooner in the pipeline fixed it.

I can still measure some difference, but it is in the < 2% range,
so it's much more tolerable.

also : it doesn't matter anymore in which order are selected
commands `-b` and `-d`.
The combination always triggers bench_decodeOnly mode.

programs/bench.c
programs/zstdcli.c

index b4cd619c4e0f85d076313a964af7c1a95d1a38e7..39ac0dc5e11d7af89662422da1b8b2fcd7216dad 100644 (file)
@@ -260,7 +260,11 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
     }   }   }
 
     /* warmimg up memory */
-    RDG_genBuffer(compressedBuffer, maxCompressedSize, 0.10, 0.50, 1);
+    if (g_decodeOnly) {
+        memcpy(compressedBuffer, srcBuffer, loadedCompressedSize);
+    } else {
+        RDG_genBuffer(compressedBuffer, maxCompressedSize, 0.10, 0.50, 1);
+    }
 
     /* Bench */
     {   U64 fastestC = (U64)(-1LL), fastestD = (U64)(-1LL);
@@ -373,9 +377,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
                             ratioAccuracy, ratio,
                             cSpeedAccuracy, compressionSpeed );
                 }
-            } else {   /* g_decodeOnly */
-                memcpy(compressedBuffer, srcBuffer, loadedCompressedSize);
-            }
+            }  /* if (!g_decodeOnly) */
 
 #if 0       /* disable decompression test */
             dCompleted=1;
index 05230227f0a7674bc35365dd5b86bc7298064801..3fd3282b15a9d1e60a6d829a1eb53cde17b2c95d 100644 (file)
@@ -573,7 +573,8 @@ int main(int argCount, const char* argv[])
                          /* Decoding */
                     case 'd':
 #ifndef ZSTD_NOBENCH
-                            if (operation==zom_bench) { BMK_setDecodeOnlyMode(1); argument++; break; }  /* benchmark decode (hidden option) */
+                            BMK_setDecodeOnlyMode(1);
+                            if (operation==zom_bench) { argument++; break; }  /* benchmark decode (hidden option) */
 #endif
                             operation=zom_decompress; argument++; break;