]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
added additional tests for performance, allowed force compression level for testing...
authorPaul Cruz <paulcruz74@fb.com>
Thu, 13 Jul 2017 21:46:54 +0000 (14:46 -0700)
committerPaul Cruz <paulcruz74@fb.com>
Thu, 13 Jul 2017 21:46:54 +0000 (14:46 -0700)
contrib/adaptive-compression/adapt.c
contrib/adaptive-compression/test-performance.sh

index 81027666bd9818ccdf3c2998392d6cfb33c03b31..c2160714d26029e7c0d95601e7a185f2744a9b9f 100644 (file)
@@ -33,6 +33,7 @@ static UTIL_time_t g_startTime;
 static size_t g_streamedSize = 0;
 static unsigned g_useProgressBar = 0;
 static UTIL_freq_t g_ticksPerSecond;
+static unsigned g_forceCompressionLevel = 0;
 
 typedef struct {
     void* start;
@@ -223,34 +224,39 @@ static void waitUntilAllJobsCompleted(adaptCCtx* ctx)
  */
 static unsigned adaptCompressionLevel(adaptCCtx* ctx)
 {
-    unsigned reset = 0;
-    unsigned const allSlow = ctx->adaptParam < ctx->stats.compressedCounter && ctx->adaptParam < ctx->stats.writeCounter && ctx->adaptParam < ctx->stats.readyCounter;
-    unsigned const compressWaiting = ctx->adaptParam < ctx->stats.readyCounter;
-    unsigned const writeWaiting = ctx->adaptParam < ctx->stats.compressedCounter;
-    unsigned const createWaiting = ctx->adaptParam < ctx->stats.writeCounter;
-    unsigned const writeSlow = ((compressWaiting && createWaiting) || (createWaiting && !writeWaiting));
-    unsigned const compressSlow = ((writeWaiting && createWaiting) || (writeWaiting && !compressWaiting));
-    unsigned const createSlow = ((compressWaiting && writeWaiting) || (compressWaiting && !createWaiting));
-    DEBUG(3, "ready: %u compressed: %u write: %u\n", ctx->stats.readyCounter, ctx->stats.compressedCounter, ctx->stats.writeCounter);
-    if (allSlow) {
-        reset = 1;
+    if (g_forceCompressionLevel) {
+        return g_compressionLevel;
     }
-    else if ((writeSlow || createSlow) && ctx->compressionLevel < (unsigned)ZSTD_maxCLevel()) {
-        DEBUG(3, "increasing compression level %u\n", ctx->compressionLevel);
-        ctx->compressionLevel++;
-        reset = 1;
-    }
-    else if (compressSlow && ctx->compressionLevel > 1) {
-        DEBUG(3, "decreasing compression level %u\n", ctx->compressionLevel);
-        ctx->compressionLevel--;
-        reset = 1;
-    }
-    if (reset) {
-        ctx->stats.readyCounter = 0;
-        ctx->stats.writeCounter = 0;
-        ctx->stats.compressedCounter = 0;
+    else {
+        unsigned reset = 0;
+        unsigned const allSlow = ctx->adaptParam < ctx->stats.compressedCounter && ctx->adaptParam < ctx->stats.writeCounter && ctx->adaptParam < ctx->stats.readyCounter;
+        unsigned const compressWaiting = ctx->adaptParam < ctx->stats.readyCounter;
+        unsigned const writeWaiting = ctx->adaptParam < ctx->stats.compressedCounter;
+        unsigned const createWaiting = ctx->adaptParam < ctx->stats.writeCounter;
+        unsigned const writeSlow = ((compressWaiting && createWaiting) || (createWaiting && !writeWaiting));
+        unsigned const compressSlow = ((writeWaiting && createWaiting) || (writeWaiting && !compressWaiting));
+        unsigned const createSlow = ((compressWaiting && writeWaiting) || (compressWaiting && !createWaiting));
+        DEBUG(3, "ready: %u compressed: %u write: %u\n", ctx->stats.readyCounter, ctx->stats.compressedCounter, ctx->stats.writeCounter);
+        if (allSlow) {
+            reset = 1;
+        }
+        else if ((writeSlow || createSlow) && ctx->compressionLevel < (unsigned)ZSTD_maxCLevel()) {
+            DEBUG(3, "increasing compression level %u\n", ctx->compressionLevel);
+            ctx->compressionLevel++;
+            reset = 1;
+        }
+        else if (compressSlow && ctx->compressionLevel > 1) {
+            DEBUG(3, "decreasing compression level %u\n", ctx->compressionLevel);
+            ctx->compressionLevel--;
+            reset = 1;
+        }
+        if (reset) {
+            ctx->stats.readyCounter = 0;
+            ctx->stats.writeCounter = 0;
+            ctx->stats.compressedCounter = 0;
+        }
+        return ctx->compressionLevel;
     }
-    return ctx->compressionLevel;
 }
 
 static size_t getUseableDictSize(unsigned compressionLevel)
@@ -649,6 +655,9 @@ int main(int argCount, const char* argv[])
                     forceStdout = 1;
                     outFilename = stdoutmark;
                     break;
+                case 'f':
+                    g_forceCompressionLevel = 1;
+                    break;
                 default:
                     DISPLAY("Error: invalid argument provided\n");
                     ret = 1;
index 6a88325d570c3ab62abbd2d06631352b010c4009..6c4991c481314ffc13aeb86cf36b48597c13d102 100755 (executable)
@@ -1,4 +1,4 @@
-echo "testing time"
+echo "testing time -- no limits set"
 ./datagen -g1GB > tmp
 time ./adapt -otmp1.zst tmp
 time zstd -1 -o tmp2.zst tmp
@@ -14,7 +14,7 @@ time ./adapt -otmp1.zst tmp
 time zstd -1 -o tmp2.zst tmp
 rm tmp*
 
-echo -e "\ntesting compression ratio"
+echo -e "\ntesting compression ratio -- no limits set"
 ./datagen -g1GB > tmp
 time ./adapt -otmp1.zst tmp
 time zstd -1 -o tmp2.zst tmp
@@ -32,3 +32,28 @@ time ./adapt -otmp1.zst tmp
 time zstd -1 -o tmp2.zst tmp
 ls -l tmp1.zst tmp2.zst
 rm tmp*
+
+echo e "\ntesting performance at various compression levels -- no limits set"
+./datagen -g1GB > tmp
+echo "adapt"
+time ./adapt -i5 -f tmp -otmp1.zst
+echo "zstdcli"
+time zstd -5 tmp -o tmp2.zst
+ls -l tmp1.zst tmp2.zst
+rm tmp*
+
+./datagen -g1GB > tmp
+echo "adapt"
+time ./adapt -i10 -f tmp -otmp1.zst
+echo "zstdcli"
+time zstd -10 tmp -o tmp2.zst
+ls -l tmp1.zst tmp2.zst
+rm tmp*
+
+./datagen -g1GB > tmp
+echo "adapt"
+time ./adapt -i15 -f tmp -otmp1.zst
+echo "zstdcli"
+time zstd -15 tmp -o tmp2.zst
+ls -l tmp1.zst tmp2.zst
+rm tmp*