Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Between xz, gzip, and bzip2, which compression algorithm gives the smallest file size and fastest speed when compressing fairly large tarballs?

share|improve this question
    
'the best' as in 'resulting in the smallest filesize' ? –  Hennes Apr 10 '13 at 18:53
    
I don't know, I was trying to find someway to word the question so I could add my test as an answer. I also have no idea why this thing was closed. @Karan –  Nathan2055 Apr 10 '13 at 22:45
    
Oh, why it was closed it easy. "Best" is highly subjective and usually leads to discussions or non-constructive answers. Best compression can be smallest file size, fastest compression, least power used to compress (e.g. on a laptop), least influence on the system while compressing (e.g. ancient single treaded programs using only one of the cores), ... or a combination of all of those. –  Hennes Apr 11 '13 at 5:10
    
An interesting article to read is tomshardware.com/reviews/winrar-winzip-7-zip-magicrar,3436.html (windows based, and focussing on 7zip, magicRAR, WinRAR and WinZip rather than xz, gz or bz, but still interesting and providing background information). –  Hennes Apr 11 '13 at 5:13
    
@Hennes - I cleaned up the post to replace best with exactly what I was researching. Also, thanks for the article you mentioned, I will read it later today. –  Nathan2055 Apr 11 '13 at 18:45

3 Answers 3

up vote 5 down vote accepted

In my stress test, I compressed 464 megabytes of data using the three formats listed. Gzip returned a 364 MB file. Bzip2 returned a 315 MB file. Xz returned a 254 MB file. I also did a simple speed test:

Compression:

1: Gzip

2: Xz

3: Bzip2 (my fan was blowing quite a bit while this was going, indicating that my Athlon II was fairly strained)

Decompression:

1: Xz

2: Gzip

3: Bzip2

Please note that all of these tests were done with the latest version of 7-Zip.

Xz is the best format for well-rounded compression, while Gzip is very good for speed. Bzip2 is decent for its compression ratio, although xz should probably be used in its place.

share|improve this answer
    
Good research. Have you tried the various compression level options offered by (at least) bzip2, e.g. bzip2 -9 <file>? –  Aaron Miller Apr 10 '13 at 20:54
    
@AaronMiller - No, is it possible to use those via 7-Zip? –  Nathan2055 Apr 15 '13 at 21:35
    
It appears so, though I'm not sure to what extent: see dotnetperls.com/7-zip-examples , section "Switch m". –  Aaron Miller Apr 16 '13 at 13:35
2  
Out of curiosity, what sort of data was the test file? –  GeminiDomino Dec 31 '13 at 23:35

I did my own benchmark on 1.1GB Linux installation vmdk image:

rar    =260MB   comp= 85s   decomp= 5s
7z(p7z)=269MB   comp= 98s   decomp=15s
tar.xz =288MB   comp=400s   decomp=30s
tar.bz2=382MB   comp= 91s   decomp=70s
tar.gz =421MB   comp=181s   decomp= 5s

all compression levels on max, CPU Intel I7 3740QM, Memory 32GB 1600, source and destination on RAM disk

I Generally use rar or 7z for archiving normal files like documents.
and for archiving system files I use .tar.gz or .tar.xz by file-roller or tar with -z or -J options along with --preserve to compress natively with tar and preserve permissions (also alternatively .tar.7z or .tar.rar can be used)

update: as tar only preserve normal permissions and not ACLs anyway, also plain .7z plus backup and restoring permissions and ACLs manually via getfacl and sefacl can be used which seems to be best option for both file archiving or system files backup because it will full preserve permissions and ACLs, has checksum, integrity test and encryption capability, only downside is that p7zip is not available everywhere

share|improve this answer

I think that this article provides very interesting results.

http://pokecraft.first-world.info/wiki/Quick_Benchmark:_Gzip_vs_Bzip2_vs_LZMA_vs_XZ_vs_LZ4_vs_LZO

The most size efficient formats are xz and lzma, both with the -e parameter passed.

The fastest algorithm are by far lzop and lz4 which can produce a compression level not very far from gzip in 1.3 seconds while gzip took 8.1 second. The compression ratio is 2.8 for lz4 and 3.7 for gzip.

Here are a few results I extracted from this article :

  • Gzip : 8.1s @ 3.7

  • lz4 : 1.3s @ 2.8

  • xz : 32.2s @ 5.43

  • xz -e : 6m40 @ 7.063

  • xz : 4m51s @ 7.063

So if you really desperatly need speed, lz4 is awesome and still provides a 2.8 compression ratio.

If you desperatly need to spare the byte, xz at the maximum compression level (9) does the best job for text files like the kernel source. However, it is very long and takes a lot of memory.

An good one where needed to minimize the impact on time AND space is gzip. This is the one i would use to make manual daily backups of a production environment.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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