Gzip vs Zstd: A Performance Comparison
A comparison between two compression techniques gzip and zstd
Introduction
I have a collection of files and folders containing JavaScript, Node.js modules, Python, and C/C++ files from various mini projects. The total size is 3 GB, and while I don’t need them all the time, I still want to archive them for occasional use. I usually use gzip for compression, but I’m currently experimenting with the newer and more efficient zstd compression. In this blog post, I’ll be comparing the compression performance of gzip and zstd.
System Specifications
- Operating System: Arch Linux
- Processor: Ryzen 5 5500U (6c/12t)
- RAM: 8GB
Compression
gzip with pigz
Using pigz
, a parallel implementation of gzip:
tar -c -I"pigz" -f temp.tar.gz temp
- Time taken : 40 seconds
- CPU usage : 50%
- File Size : 848MB
zstd
The zstd compression algorithm offers a range of compression levels from 1-19, where 1 is least compression and 19 is highest compression. Using higher compression levels requires more cpu power and time. Therefore i have choosen a sweet spot and decided on level 3 and 19.
zstd (Level 3)
Using zstd with level 3(default)
tar c -I"zstd -T0" -f temp.tar.zst temp
- Time taken : 27 seconds
- CPU usage : 15%
- File Size : 770MB
zstd (Level 19)
Using zstd with level 19
tar c -I"zstd -19 -T0" -f temp.tar.zst temp
- Time taken : 4 minutes 2 seconds
- CPU usage : 50%
- File Size : 593MB
Extraction
gzip with pigz
tar -x -Ipigz -f temp.tar.gz -C temp
- Time taken : 56 seconds
- CPU Usage : 10%
zstd (Level 3)
tar -x --zstd -f temp.tar.zst -C temp
- Time taken : 52 seconds
- CPU Usage : 7%
zstd (Level 19)
tar -x --zstd -f temp.tar.zst -C temp
- Time taken : 50 seconds
- CPU Usage : 7%
Conclusion
Clearly, the zstd level 19 achieves a smaller size file but comes at the cost of increased CPU power and time consumption. However, using the default zstd (level 3) proves to be a more efficient choice compared to gzip, giving a balance between compression performance and resource utilization. Additionally, the decompression almost similar regardless of which level.