summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-12-06 21:53:39 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-10-10 23:05:44 -0400
commit9f35e8b45894f7e201878e128ca371662a9dc63d (patch)
tree780276c43ce4e6209829f393260ea7d33e7db75b
parent4b5bc5396c090ee41c45cab9052372d296c4a2f4 (diff)
test-compress-benchmark: test three cases (zeros, simple, semi-random)
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.
-rw-r--r--src/journal/test-compress-benchmark.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/journal/test-compress-benchmark.c b/src/journal/test-compress-benchmark.c
index c8e5b76c6c..0be6820a14 100644
--- a/src/journal/test-compress-benchmark.c
+++ b/src/journal/test-compress-benchmark.c
@@ -20,6 +20,7 @@
#include "compress.h"
#include "util.h"
#include "macro.h"
+#include "random-util.h"
typedef int (compress_t)(const void *src, uint64_t src_size, void *dst, size_t *dst_size);
typedef int (decompress_t)(const void *src, uint64_t src_size,
@@ -27,20 +28,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_se(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 +62,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_se(text && buf);
@@ -62,7 +74,8 @@ static void test_compress_decompress(const char* label,
r = compress(text, i, buf, &j);
/* assume compression must be successful except for small inputs */
- assert_se(r == 0 || (i < 2048 && r == -ENOBUFS));
+ assert_se(r == 0 || (i < 2048 && r == -ENOBUFS) || streq(type, "random"));
+
/* check for overwrites */
assert_se(buf[i] == 0);
if (r != 0) {
@@ -91,23 +104,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;
}