Commit 47fca515 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

[zlib-bench] Add compression strategy support

Mainly for my research needs: allow unusal zlib compression strategies
for comparison purposes (R_HUFFMAN_ONLY, Z_RLE).

Bug: 798943
Change-Id: I8a699e68a055df12c08f38d7156769f10f12e90f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2148912
Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org>
Auto-Submit: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarAdenilson Cavalcanti <cavalcantii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759007}
parent eb06fcda
......@@ -102,7 +102,22 @@ const char* zlib_wrapper_name(zlib_wrapper type) {
return 0;
}
static int zlib_compression_level;
static int zlib_strategy = Z_DEFAULT_STRATEGY;
const char* zlib_level_strategy_name(int compression_level) {
if (compression_level == 0)
return ""; // strategy is meaningless at level 0
if (zlib_strategy == Z_HUFFMAN_ONLY)
return "huffman ";
if (zlib_strategy == Z_RLE)
return "rle ";
if (zlib_strategy == Z_DEFAULT_STRATEGY)
return "";
error_exit("bad strategy", zlib_strategy);
return 0;
}
static int zlib_compression_level = Z_DEFAULT_COMPRESSION;
void zlib_compress(
const zlib_wrapper type,
......@@ -119,7 +134,7 @@ void zlib_compress(
memset(&stream, 0, sizeof(stream));
int result = deflateInit2(&stream, zlib_compression_level, Z_DEFLATED,
zlib_stream_wrapper_type(type), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
zlib_stream_wrapper_type(type), MAX_MEM_LEVEL, zlib_strategy);
if (result != Z_OK)
error_exit("deflateInit2 failed", result);
......@@ -185,7 +200,12 @@ void zlib_file(const char* name, const zlib_wrapper type) {
const auto file = read_file_data_or_exit(name);
const int length = static_cast<int>(file.size);
const char* data = file.data.get();
printf("%-40s :\n", name);
/*
* Report compression strategy and file name.
*/
const char* strategy = zlib_level_strategy_name(zlib_compression_level);
printf("%s%-40s :\n", strategy, name);
/*
* Chop the data into blocks.
......@@ -302,10 +322,18 @@ int main(int argc, char* argv[]) {
else
usage_exit(argv[0]);
if (!get_option(argc, argv, "--compression"))
zlib_compression_level = Z_DEFAULT_COMPRESSION;
else if (!get_compression(argc, argv, &zlib_compression_level))
usage_exit(argv[0]);
while (argn < argc && !strncmp(argv[argn], "--", 2)) {
if (get_option(argc, argv, "--compression")) {
if (!get_compression(argc, argv, &zlib_compression_level))
usage_exit(argv[0]);
} else if (get_option(argc, argv, "--huffman")) {
zlib_strategy = Z_HUFFMAN_ONLY;
} else if (get_option(argc, argv, "--rle")) {
zlib_strategy = Z_RLE;
} else {
usage_exit(argv[0]);
}
}
if (argn >= argc)
usage_exit(argv[0]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment