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?
2 Answers 2
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.
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:
compressis slower thangzip -1when 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.
-
What about
pigz(should be much faster thangzip) and why is the compress time noch available for-9?mgutt– mgutt2021-08-19 06:10:10 +00:00Commented 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
compressis pretty dated. It's only faster when decompressing, andpigzdoes not improve that iirc/afaik because it only multithreads the compression.Luc– Luc2021-08-19 13:58:53 +00:00Commented Aug 19, 2021 at 13:58 -
I didn't tested it by myself, but he says
pigzgives a "significant improvement" on decompressing: serverfault.com/a/270825/44086mgutt– mgutt2021-08-19 16:08:01 +00:00Commented 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 :)Luc– Luc2021-08-20 10:22:54 +00:00Commented Aug 20, 2021 at 10:22
compressis 80s technology,gzip90s,bzip200s,xz10s.