[systemd-devel] [PATCH 3/3] test-compress-benchmark: test three cases (zeros, simple, semi-random)

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Sun Dec 7 10:32:40 PST 2014


Existing test would use highly-compressible repeatable
input. Two types of input are added:
- zeros
- random blocks interspersed with zeros

The idea is to get more information about behaviour in various cases.

On Intel Xeon the results are:

% ./test-compress-benchmark
XZ/zeros: compressed & decompressed 2535301373 bytes in 32.56s (74.26MiB/s), mean compresion 99.96%, skipped 3160 bytes
LZ4/zeros: compressed & decompressed 2535304362 bytes in 1.16s (2088.69MiB/s), mean compresion 99.60%, skipped 171 bytes
XZ/simple: compressed & decompressed 2535300963 bytes in 30.42s (79.48MiB/s), mean compresion 99.95%, skipped 3570 bytes
LZ4/simple: compressed & decompressed 2535303543 bytes in 1.22s (1978.86MiB/s), mean compresion 99.60%, skipped 990 bytes
XZ/random: compressed & decompressed 381756649 bytes in 60.02s (6.07MiB/s), mean compresion 39.64%, skipped 27813723 bytes
LZ4/random: compressed & decompressed 2507385036 bytes in 0.97s (2477.52MiB/s), mean compresion 54.77%, skipped 27919497 bytes

If someone has ideas for more realistic test cases, they can be easily
added to this framework.
---
 src/journal/test-compress-benchmark.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/src/journal/test-compress-benchmark.c b/src/journal/test-compress-benchmark.c
index b3bc3ec2fe..af1dcc4122 100644
--- a/src/journal/test-compress-benchmark.c
+++ b/src/journal/test-compress-benchmark.c
@@ -27,20 +27,31 @@ typedef int (decompress_t)(const void *src, uint64_t src_size,
 
 #define MAX_SIZE (1024*1024LU)
 
-static char* make_buf(size_t count) {
+static char* make_buf(size_t count, const char *type) {
         char *buf;
         size_t i;
 
         buf = malloc(count);
         assert(buf);
 
-        for (i = 0; i < count; i++)
-                buf[i] = 'a' + i % ('z' - 'a' + 1);
+        if (streq(type, "zeros"))
+                memzero(buf, count);
+        else if (streq(type, "simple"))
+                for (i = 0; i < count; i++)
+                        buf[i] = 'a' + i % ('z' - 'a' + 1);
+        else if (streq(type, "random")) {
+                random_bytes(buf, count/10);
+                random_bytes(buf + 2*count/10, count/10);
+                random_bytes(buf + 4*count/10, count/20);
+                random_bytes(buf + 6*count/10, count/20);
+                random_bytes(buf + 8*count/10, count/20);
+        } else
+                assert_not_reached("here");
 
         return buf;
 }
 
-static void test_compress_decompress(const char* label,
+static void test_compress_decompress(const char* label, const char* type,
                                      compress_t compress, decompress_t decompress) {
         usec_t n, n2 = 0;
         float dt;
@@ -50,7 +61,7 @@ static void test_compress_decompress(const char* label,
         size_t buf2_allocated = 0;
         size_t skipped = 0, compressed = 0, total = 0;
 
-        text = make_buf(MAX_SIZE);
+        text = make_buf(MAX_SIZE, type);
         buf = calloc(MAX_SIZE + 1, 1);
         assert(text && buf);
 
@@ -62,7 +73,7 @@ static void test_compress_decompress(const char* label,
 
                 r = compress(text, i, buf, &j);
                 /* assume compression must be successful except for small inputs */
-                assert(r == 0 || (i < 2048 && r == -ENOBUFS));
+                assert(r == 0 || (i < 2048 && r == -ENOBUFS) || streq(type, "random"));
                 /* check for overwrites */
                 assert(buf[i] == 0);
                 if (r != 0) {
@@ -91,23 +102,26 @@ static void test_compress_decompress(const char* label,
 
         dt = (n2-n) / 1e6;
 
-        log_info("%s: compressed & decompressed %zu bytes in %.2fs (%.2fMiB/s), "
+        log_info("%s/%s: compressed & decompressed %zu bytes in %.2fs (%.2fMiB/s), "
                  "mean compresion %.2f%%, skipped %zu bytes",
-                 label, total, dt,
+                 label, type, total, dt,
                  total / 1024. / 1024 / dt,
                  100 - compressed * 100. / total,
                  skipped);
 }
 
 int main(int argc, char *argv[]) {
+        const char *i;
 
         log_set_max_level(LOG_DEBUG);
 
+        NULSTR_FOREACH(i, "zeros\0simple\0random\0") {
 #ifdef HAVE_XZ
-        test_compress_decompress("XZ", compress_blob_xz, decompress_blob_xz);
+                test_compress_decompress("XZ", i, compress_blob_xz, decompress_blob_xz);
 #endif
 #ifdef HAVE_LZ4
-        test_compress_decompress("LZ4", compress_blob_lz4, decompress_blob_lz4);
+                test_compress_decompress("LZ4", i, compress_blob_lz4, decompress_blob_lz4);
 #endif
+        }
         return 0;
 }
-- 
1.9.3



More information about the systemd-devel mailing list