Wednesday, January 10, 2018

Which Is The Best Compression Tool For Linux?

https://www.lifewire.com/which-is-the-best-compression-tool-for-linux-4082712

Introduction

When it comes to finding file compression tools in Linux you are left with a number of different choices but which one is the best?
In this guide, I will put zip, gzip and bzip2 through their paces to see which one is best.
I have conducted a number of tests against different file types and using different settings for each tool and here are the results

Best Tool For Compressing Windows Documents

Before looking at a more detailed test I wanted to try each compression tool against a single file type so that we could see how each tool handles the file in question.
These tests have been run against the Microsoft DOCX format.
Default Settings
I have started with default settings for each program.
ToolFile Size
Initial Filesize12202 bytes
zip9685
gzip9537
bzip210109
Best Compression
This time I have gone for maximum compression,
ToolFile Size
Initial Filesize12202 bytes
zip9677
gzip9530
bzip210109
To make sure this wasn't a fluke I tried the same test against 2 other documents.
File 1:
ToolFile Size
Initial Filesize14913176
zip14657475
gzip14657328
bzip214741042
File 2:
ToolFile Size
Initial Filesize13314
zip10814
gzip10653
bzip211254
Two of the files contained text only whereas the larger file contained a lot of pages of text with lots of images and a lot of formatting.
From the first test gzip comes out on top in all categories and bzip2 is the least effective.

Best Tool For Compressing Images

This time I am going to show the results of compressing various image formats such as PNG and JPG.
In theory, JPG files are already compressed and therefore may not compress at all and could, in theory, make the file bigger.
PNG File
ToolFile Size
Initial Filesize345265
zip345399
gzip345247
bzip2346484
JPEG File
ToolFile Size
Initial Filesize44340
zip44165
gzip44015
bzip244281
Bitmap File
ToolFile Size
Initial Filesize3113334
zip495028
gzip494883
bzip2397569
GIF File
ToolFile Size
Initial Filesize6164
zip5772
gzip5627
bzip26051
In all cases, gzip came out on top again except for one and that was the humble bitmap. The bzip2 compression produced a tiny file in comparison to the original.

Best Tool For Compressing Audio Files

The most common audio format is MP3 and in theory, this has already been compressed so the tools may actually end up increasing the file size.
I am going to test two files:
File 1:
ToolFile Size
Initial Filesize5278905
zip5270224
gzip5270086
bzip25270491
File 2:
ToolFile Size
Initial Filesize4135331
zip4126138
gzip4126000
bzip24119410
This time the results were inconclusive. The compression in all cases was minimal but it is interesting that bzip2 came out the worst for file 1 and the best for file 2.

Best Tool For Compressing Video

In this test, I am going to compress 2 video files. As with MP3 the MP4 file already contains a level of compression and so the results will probably prove to be negligible in terms of how well the tools perform.
I have also included an FLV file which will not have any level of compression as it is a lossless format.
MP4:
ToolFile Size
Initial Filesize731908
zip478546
gzip478407
bzip2478042

Yet again the bzip2 format came out better than the other file types.
At this stage, it would seem that there is little difference as to which tool you use. The results are close across the board for all file types and sometimes gzip is best and others bzip2 is best and the zip command is usually there or thereabouts.
FLV:
ToolFile Size
Initial Filesize7833634
zip4339169
gzip4339030
bzip24300295

It would appear that if you are compressing video that bzip2 is the compression tool of choice.

Executables

The last single category that I will try is executables.
As executables are compiled the code I suspect that they won't compress very well.
File 1:
ToolFile Size
Initial Filesize26557472
zip26514031
gzip26513892
bzip226639209
File 2:
ToolFile Size
Initial Filesize195629144
zip193951631
gzip193951493
bzip2194834876

Again we see that gzip comes out on top and bzip2 comes last. For the smaller executable the bzip file actually grew in size.

Complete Folder Test

Thus far I have dealt with individual files. This time I have a folder full of images, documents, spreadsheets, videos, audio files, executables and many other different file formats.
I have created a tar file which makes it easier to compress using all of the tools available. The gzip and bzip2 commands work against single files whereas the zip command can work against folders.
By using the tar command I have created a single file which contains all of the folders and files in an uncompressed format.
I am going to monitor a number of things in this test:
  • Compress using default compression settings - report results by file sizes
  • Compress using default compression settings - report results by time was taken
  • Compress using best compression - report results by file sizes
  • Compress using best compression - report results by time was taken
  • Compress using fastest compression - report results by file sizes
  • Compress using fastest compression - report results by time taken
Default Compression
ToolFile SizeTime Taken
Initial File13330841600
zip13031777781 minute 10 seconds
gzip13031776371 minute 35 seconds
bzip213092349476 minutes 5 seconds
Maximum Compression
ToolFile SizeTime Taken
Initial File13330841600
zip13031078941 minute 10 seconds
gzip13031077531 minute 35 seconds
bzip213092349476 minutes 10 seconds
Fastest Compression
ToolFile SizeTime Taken
Initial File13330841600
zip13041639431 minute 0 seconds
gzip13041638021 minute 15 seconds
bzip213135575956 minutes 10 seconds
Summary
Based on the final test it is clear that bzip2 is not as useful as the other 2 compression tools. It takes longer to compress the files and the final file size is larger.
The difference between zip and gzip is negligible, and whilst gzip generally comes out on top, the zip format is more common across different operating systems.
So my verdict is that definitely use either zip or gzip but maybe bzip2 has had its day and needs to be confined to history.

No comments:

Post a Comment