145

I've known gzip for years, recently I saw bzip being used at work. Are they basically equivalent, or are there significant pros and cons to one of them over the other?

5

6 Answers 6

180

Gzip and bzip2, as well as xz and lzop, are functionally equivalent. (There once was a bzip, but it seems to have completely vanished off the face of the world.) Other common compression formats are zip, rar and 7z; these three do both compression and archiving (packing multiple files into one). Here are some typical ratings in terms of speed, availability and typical compression ratio (note that these ratings are somewhat subjective, don't take them as gospel):

decompression speed (fast > slow): lzop > gzip, zip > xz > 7z > rar > bzip2
compression speed (fast > slow): lzop > gzip, zip > xz > bzip2 > 7z > rar
compression ratio (better > worse): xz > 7z > rar, bzip2 > gzip > zip > lzop
availability (unix): gzip > bzip2 > xz > lzop > zip > 7z > rar
availability (windows): zip > rar > 7z > gzip > bzip2, lzop, xz

As you can see, there isn't a clear winner. If you want to rely on programs that are likely to be installed already, use zip on Windows (or if possible, self-extracting archives, as Windows doesn't ship with any of these) and gzip on unix. If you want maximum compression, use 7z or xz.

Non-Unix native formats (zip, rar, 7z) don't preserve all Unix metadata (ownership, permissions). If you need that, use compressed tar.

Rar also has downside that, as far as I know, there is no open source software that creates rar archives or that can unpack all rar archives. The other formats have free implementations and no (serious) patent claims.

12
  • 3
    as far as I can tell, all versions of Windows since XP, can open zip file natively using the file explorern
    – Lie Ryan
    Nov 2, 2010 at 15:00
  • 22
    @new123456 On OpenBSD, gzip is in the base system but bzip2 has to be installed from a package. Many *WRT routers include gzip but not bzip2. Jul 3, 2011 at 17:53
  • 2
    @Gilles I can confirm that my DD-WRT Release: 08/12/10 (SVN revision: 14929) does not have bzip2, but does have gzip.
    – Urda
    Mar 31, 2012 at 16:10
  • 16
    @mlainz Original research. This isn't Wikipedia. Jan 23, 2016 at 10:09
  • 4
    it seems to have completely vanished - Plain old bzip vanished because it was using the patented algorithmic coding. Because of the patent, it was re-designed to use Huffman coding instead. During this re-design, new features and improvements were added. The fundamental thing that makes it a unique compression algorithm though, the Burrows–Wheeler transform, stayed the same in both versions.
    – forest
    Jan 1, 2019 at 3:23
27

As far as I can tell, gzip is overall faster, while bzip overall produces better (smaller) compression.

7
  • 1
    Also, gzip seems to be slightly better supported, especially on Windows..
    – Dentrasi
    Oct 30, 2010 at 17:32
  • 6
    @Dentrasi: winrar/7zip support both, what's the problem?
    – whitequark
    Oct 31, 2010 at 4:26
  • @whitequark: being widely supported is mostly important for unix since users may not have root access and must work with what is already installed. Also applies to Windows environments where the user does not have admin access (schools/libraries/etc).
    – Matthew
    Nov 26, 2012 at 19:23
  • 5
    @Matthew, you don't need admin rights to use a lot of ported free software, including 7zip.
    – whitequark
    Nov 28, 2012 at 0:26
  • 1
    @IQAndreas: some benchmarks: 1, 2, 3
    – Lie Ryan
    Feb 9, 2016 at 12:45
8

The algorithms have different time, memory, space tradeoffs. Bear in mind these algorithms were written quite a while back and your smartphone has many times more CPU than desktops of those days.

Your pick is between universality (.gz) and a bit more compression (.bz2). Only you can say whichyou care about more.

One advantage of .gz is that it can compress a stream, a sequence where you can't look behind. This makes it the official compressor of http streams. I needed to use gzip once because of that, but unlikely you'll need to think about it.

2
  • 3
    Another way to phrase "gz can compress a stream" is that gz is homomorphic under concatenation: gz(concat(x, y)) == concat(gz(x), gz(y)). IMO this is one of gz's most useful features. Mar 4, 2020 at 16:57
  • @BallpointBen you hit the nail on its head. Couldn't have explained it any better. May 10 at 14:28
4

Here is a list of sites that test compression algorithms, to find just bzip and gzip you will have to do some digging, but most sites will list characteristics of the algorithms. This way you can compare what is important to you, size (compression ratio), time, memory, cpu.
http://www.maximumcompression.com/benchmarks/benchmarks.php

1
  • The link you referenced is dead. May 10 at 14:25
1

In my experience bzip has offered consistently better compression ratios than gzip. Plus with 7zip as manager and bzip algorithm, 7zip can make use of multi core processors.

1

Per http://tukaani.org/lzma/benchmarks.html , gzip compresses twice as fast as bzip2, and decompresses ten times as fast.

Eg for use with s3 caching, on travis etc, where you want speed of compress/decompress, not just small sizes, gzip might be a good trade-off.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.