@@ -236,7 +236,11 @@ void check_file(const Data& file, zlib_wrapper type, int mode) {
236
236
error_exit (" check file: error writing output" , 3 );
237
237
}
238
238
239
- void zlib_file (const char * name, zlib_wrapper type, int width, int check) {
239
+ void zlib_file (const char * name,
240
+ zlib_wrapper type,
241
+ int width,
242
+ int check,
243
+ bool output_csv_format) {
240
244
/*
241
245
* Read the file data.
242
246
*/
@@ -257,7 +261,9 @@ void zlib_file(const char* name, zlib_wrapper type, int width, int check) {
257
261
* Report compression strategy and file name.
258
262
*/
259
263
const char * strategy = zlib_level_strategy_name (zlib_compression_level);
260
- printf (" %s%-40s :\n " , strategy, name);
264
+ if (!output_csv_format) {
265
+ printf (" %s%-40s :\n " , strategy, name);
266
+ }
261
267
262
268
/*
263
269
* Chop the data into blocks.
@@ -329,19 +335,28 @@ void zlib_file(const char* name, zlib_wrapper type, int width, int check) {
329
335
std::sort (ctime , ctime + runs);
330
336
std::sort (utime, utime + runs);
331
337
332
- double deflate_rate_med = length * repeats / mega_byte / ctime [runs / 2 ];
333
- double inflate_rate_med = length * repeats / mega_byte / utime[runs / 2 ];
334
- double deflate_rate_max = length * repeats / mega_byte / ctime [0 ];
335
- double inflate_rate_max = length * repeats / mega_byte / utime[0 ];
336
-
337
- // type, block size, compression ratio, etc
338
- printf (" %s: [b %dM] bytes %*d -> %*u %4.2f%%" ,
339
- zlib_wrapper_name (type), block_size / (1 << 20 ), width, length, width,
340
- unsigned (output_length), output_length * 100.0 / length);
341
-
342
- // compress / uncompress median (max) rates
343
- printf (" comp %5.1f (%5.1f) MB/s uncomp %5.1f (%5.1f) MB/s\n " ,
344
- deflate_rate_med, deflate_rate_max, inflate_rate_med, inflate_rate_max);
338
+ double deflate_rate_med, inflate_rate_med, deflate_rate_max, inflate_rate_max;
339
+ deflate_rate_med = length * repeats / mega_byte / ctime [runs / 2 ];
340
+ inflate_rate_med = length * repeats / mega_byte / utime[runs / 2 ];
341
+ deflate_rate_max = length * repeats / mega_byte / ctime [0 ];
342
+ inflate_rate_max = length * repeats / mega_byte / utime[0 ];
343
+ double compress_ratio = output_length * 100.0 / length;
344
+
345
+ if (!output_csv_format) {
346
+ // type, block size, compression ratio, etc
347
+ printf (" %s: [b %dM] bytes %*d -> %*u %4.2f%%" , zlib_wrapper_name (type),
348
+ block_size / (1 << 20 ), width, length, width,
349
+ unsigned (output_length), compress_ratio);
350
+
351
+ // compress / uncompress median (max) rates
352
+ printf (" comp %5.1f (%5.1f) MB/s uncomp %5.1f (%5.1f) MB/s\n " ,
353
+ deflate_rate_med, deflate_rate_max, inflate_rate_med,
354
+ inflate_rate_max);
355
+ } else {
356
+ printf (" %s\t %.5lf\t %.5lf\t %.5lf\t %.5lf\t %.5lf\n " , name, deflate_rate_med,
357
+ inflate_rate_med, deflate_rate_max, inflate_rate_max,
358
+ compress_ratio);
359
+ }
345
360
}
346
361
347
362
static int argn = 1 ;
@@ -363,8 +378,10 @@ void get_field_width(int argc, char* argv[], int& value) {
363
378
}
364
379
365
380
void usage_exit (const char * program) {
366
- static auto * options = " gzip|zlib|raw"
367
- " [--compression 0:9] [--huffman|--rle] [--field width] [--check]" ;
381
+ static auto * options =
382
+ " gzip|zlib|raw"
383
+ " [--compression 0:9] [--huffman|--rle] [--field width] [--check]"
384
+ " [--csv]" ;
368
385
printf (" usage: %s %s files ...\n " , program, options);
369
386
printf (" zlib version: %s\n " , ZLIB_VERSION);
370
387
exit (1 );
@@ -383,7 +400,7 @@ int main(int argc, char* argv[]) {
383
400
384
401
int size_field_width = 0 ;
385
402
int file_check = 0 ;
386
-
403
+ bool output_csv = false ;
387
404
while (argn < argc && argv[argn][0 ] == ' -' ) {
388
405
if (get_option (argc, argv, " --compression" )) {
389
406
if (!get_compression (argc, argv, zlib_compression_level))
@@ -398,6 +415,11 @@ int main(int argc, char* argv[]) {
398
415
file_check = 2 ;
399
416
} else if (get_option (argc, argv, " --field" )) {
400
417
get_field_width (argc, argv, size_field_width);
418
+ } else if (get_option (argc, argv, " --csv" )) {
419
+ output_csv = true ;
420
+ printf (
421
+ " filename\t compression\t decompression\t comp_max\t "
422
+ " decomp_max\t compress_ratio\n " );
401
423
} else {
402
424
usage_exit (argv[0 ]);
403
425
}
@@ -408,8 +430,9 @@ int main(int argc, char* argv[]) {
408
430
409
431
if (size_field_width < 6 )
410
432
size_field_width = 6 ;
411
- while (argn < argc)
412
- zlib_file (argv[argn++], type, size_field_width, file_check);
433
+ while (argn < argc) {
434
+ zlib_file (argv[argn++], type, size_field_width, file_check, output_csv);
435
+ }
413
436
414
437
return 0 ;
415
438
}
0 commit comments