diff --git a/bench/zrle-bench.c b/bench/zrle-bench.c index a209a3a..8e845ed 100644 --- a/bench/zrle-bench.c +++ b/bench/zrle-bench.c @@ -69,7 +69,11 @@ int run_benchmark(const char *image) z_stream zs = { 0 }; - deflateInit(&zs, Z_DEFAULT_COMPRESSION); + deflateInit2(&zs, /* compression level: */ 1, + /* method: */ Z_DEFLATED, + /* window bits: */ 15, + /* mem level: */ 9, + /* strategy: */ Z_DEFAULT_STRATEGY); void *dummy = malloc(width * height * 4); if (!dummy) @@ -92,6 +96,12 @@ int run_benchmark(const char *image) printf("Encoding %s took %"PRIu64" micro seconds\n", image, end_time - start_time); + double orig_size = width * height * 4; + double compressed_size = frame.len; + + double reduction = (orig_size - compressed_size) / orig_size; + printf("Size reduction: %.1f %%\n", reduction * 100.0); + deflateEnd(&zs); if (rc < 0) diff --git a/src/server.c b/src/server.c index f2fe829..0142d9a 100644 --- a/src/server.c +++ b/src/server.c @@ -748,7 +748,14 @@ static void on_connection(uv_stream_t *server_stream, int status) client->ref = 1; client->server = server; - if (deflateInit(&client->z_stream, Z_BEST_SPEED) != Z_OK) { + int rc = deflateInit2(&client->z_stream, + /* compression level: */ 1, + /* method: */ Z_DEFLATED, + /* window bits: */ 15, + /* mem level: */ 9, + /* strategy: */ Z_DEFAULT_STRATEGY); + + if (rc != Z_OK) { free(client); return; }