Wednesday, January 10, 2018

Which Is The Best Compression Tool For Linux?

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.

Tool

File Size

Initial Filesize

12202 bytes

zip

9685

gzip

9537

bzip2

10109

Best Compression
This time I have gone for maximum compression,

Tool

File Size

Initial Filesize

12202 bytes

zip

9677

gzip

9530

bzip2

10109

To make sure this wasn't a fluke I tried the same test against 2 other documents.File 1:

Tool

File Size

Initial Filesize

14913176

zip

14657475

gzip

14657328

bzip2

14741042

File 2:

Tool

File Size

Initial Filesize

13314

zip

10814

gzip

10653

bzip2

11254

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

Tool

File Size

Initial Filesize

345265

zip

345399

gzip

345247

bzip2

346484

JPEG File

Tool

File Size

Initial Filesize

44340

zip

44165

gzip

44015

bzip2

44281

Bitmap File

Tool

File Size

Initial Filesize

3113334

zip

495028

gzip

494883

bzip2

397569

GIF File

Tool

File Size

Initial Filesize

6164

zip

5772

gzip

5627

bzip2

6051

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:

Tool

File Size

Initial Filesize

5278905

zip

5270224

gzip

5270086

bzip2

5270491

File 2:

Tool

File Size

Initial Filesize

4135331

zip

4126138

gzip

4126000

bzip2

4119410

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:

Tool

File Size

Initial Filesize

731908

zip

478546

gzip

478407

bzip2

478042

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:

Tool

File Size

Initial Filesize

7833634

zip

4339169

gzip

4339030

bzip2

4300295

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:

Tool

File Size

Initial Filesize

26557472

zip

26514031

gzip

26513892

bzip2

26639209

File 2:

Tool

File Size

Initial Filesize

195629144

zip

193951631

gzip

193951493

bzip2

194834876

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 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

Tool

File Size

Time Taken

Initial File

1333084160

0

zip

1303177778

1 minute 10 seconds

gzip

1303177637

1 minute 35 seconds

bzip2

1309234947

6 minutes 5 seconds

Maximum Compression

Tool

File Size

Time Taken

Initial File

1333084160

0

zip

1303107894

1 minute 10 seconds

gzip

1303107753

1 minute 35 seconds

bzip2

1309234947

6 minutes 10 seconds

Fastest Compression

Tool

File Size

Time Taken

Initial File

1333084160

0

zip

1304163943

1 minute 0 seconds

gzip

1304163802

1 minute 15 seconds

bzip2

1313557595

6 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.