2

What is the difference between gzip and compress? What are the advantages of using compress function. I could see a size difference in the compressed file, but apart from this what are the main adavantages?

1
  • 4
    compress is 80s technology, gzip 90s, bzip2 00s, xz 10s. Commented Mar 10, 2015 at 14:49

2 Answers 2

6

Compress is significantly older (1983) and based on the LZW compression algorithm.

Gzip was written in the early 90's and is based on the DEFLATE algorithm.

In general Compress will run faster and use less memory, but gzip will generally reach significantly higher levels of compression.

There were also patent issues with LZW that Unisys started enforcing in the early 90's (this was mostly targeted toward the GIF format that also used LZW compression). The gzip developers intended to develop general purpose compression software that was unencumbered by patents.

2

TL;DR: gzip is better than compress. Other tools might be faster/better still, e.g. pigz is faster and gzip-compatible.

I did some tests to compare the compression level, compression time and decompression time of gzip, compress andxz (just to have a bit more context, this is not a comprehensive compression tool comparison):

File size
|    Percentage of original size
|    |    Time to compress
|    |    |    Time to decompress
|    |    |    |    Method
|    |    |    |    |        Filename
425M 100% -    -    -        Germany_hessen_europe_2.obf
348M  82% 16.8 3.24 compress test.Z
260M  61% 11.8 4.18 gzip -1  test.1.gz
246M  58% n/a  3.88 gzip -9  test.9.gz
226M  53% 69.6 15.6 xz -1    test.1.xz

The file is a map of a German state downloaded from OsmAnd, which compresses pretty well (by 50% with a bit of effort).

In short:

  • compress is slower than gzip -1 when compressing,
  • it compresses only half as well, but
  • it is 29% faster when decompressing.

Test method: I used an idle SSD and I/O was not the bottleneck. I used time cat file | compression > out for compression and time cat file | decompression > /dev/null for decompression times. Tests for gzip -1 and compress were run twice (both compress and decompress) and gave very similar results, of which I took the average. The gzip -9 compression time I simply forgot to measure, but since -1 already compresses a lot better than compress I don't think it would add much to go back and do it.

4
  • What about pigz (should be much faster than gzip) and why is the compress time noch available for -9? Commented Aug 19, 2021 at 6:10
  • 1
    @mgutt Good suggestion, and reading this back now I also feel like bzip2 is missing and zstd... but then seeing the question, it's really about the difference between gzip and compress, and I took one other (xz) as a comparison I think. So this is not supposed to be a comprehensive comparison but rather makes clear that the traditional compress is pretty dated. It's only faster when decompressing, and pigz does not improve that iirc/afaik because it only multithreads the compression. Commented Aug 19, 2021 at 13:58
  • I didn't tested it by myself, but he says pigz gives a "significant improvement" on decompressing: serverfault.com/a/270825/44086 Commented Aug 19, 2021 at 16:08
  • @mgutt Good point, I edited the summary on top, does that sound like what you meant to add? Also feel free to just submit an edit suggestion :) Commented Aug 20, 2021 at 10:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.