BZip3

Hacker News Top 工具

摘要

BZip3 是一种高性能的压缩工具,与前驱 BZip2 相比,提供更优的压缩率和速度,利用先进的算法如上下文混合熵编码和 Burrows-Wheeler 变换。

暂无内容
查看原文
查看缓存全文

缓存时间: 2026/09/07 15:30

iczelia/bzip3

来源:https://github.com/iczelia/bzip3

BZip3

构建状态 (https://github.com/iczelia/bzip3/actions/workflows/build.yml)

BZip2 更优、更快、更强的精神继承者。凭借基于零阶上下文混合熵编码器、利用后缀数组的快速Burrows-Wheeler变换,以及基于LZ77风格字符串匹配和PPM风格上下文建模的Lempel Ziv+预测RLE传递,实现了更高的压缩比和更好的性能。

与其前辈一样,BZip3 擅长压缩文本或代码

安装

# 如果使用 git 克隆(源码包不需要),首先...
$ ./bootstrap.sh

# 全部...
$ ./configure
$ make
$ sudo make install

或者,你可以尝试使用系统的包管理器安装 bzip3:

打包状态 (https://repology.org/project/bzip3/versions)

在 macOS 上,你可以使用 Homebrew (https://brew.sh) 轻松安装:

$ brew install bzip3

Perl 源代码基准测试

首先,我下载了所有已发布的 Perl5 版本并解压缩它们。

% wget -r -l1 -nH --cut-dirs=2 --no-parent -A.tar.gz --no-directories https://www.cpan.org/src/5.0/
% for g in *.gz; do gunzip $g; done
% ls -la | wc -l
262

然后,我将所有得到的 .tar 文件放入单个 .tar 文件中,并尝试使用各种压缩工具对其进行压缩:

xz -T16 -9 -k all.tar  10829.91s user 26.91s system 1488% cpu 14658M memory 12:09.24 total
bzip2 -9 -k all.tar  981.78s user 9.77s system 95% cpu 8M memory 17:16.64 total
bzip3 -e -b 256 -j 12 all.tar  2713.81s user 16.28s system 634% cpu 18301M memory 7:10.10 total
bzip3 -e -b 511 -j 4 all.tar  17.65s user 12.19s system 170% cpu 12178M memory 7:08.65 total
zstd -T12 -16 all.tar  4162.94s user 16.40s system 1056% cpu 687M memory 6:35.62 total

结果如下:

方法压缩后大小 (字节)
LZMA (xz)2’056’645’240
bzip23’441’163’911
bzip3 -b 2561’001’957’587
bzip3 -b 511546’456’978
Zstandard3’076’143’660

最后,是解压缩所需的时间(WD Blue HDD):

方法解压缩时间
LZMA (xz)4分 40秒
bzip29分 22秒
bzip3 (并行)4分 06秒
Zstandard3分 51秒

然后,我使用 lrzip 对原始 .tar 文件执行长距离去重:

% time lrzip -n -o all_none.tar.lrz all.tar
546.17s user 160.87s system 102% cpu 10970M memory 11:28.00 total

% time lrzip --lzma -o all_lzma.tar.lrz all.tar
702.16s user 161.87s system 122% cpu 10792M memory 11:44.83 total

% time lrzip -b -o all_bzip2.tar.lrz all.tar
563.93s user 147.38s system 112% cpu 10970M memory 10:34.10 total

最后,我使用 bzip3 压缩得到的 none.tar.lrz 文件:

% time bzip3 -e -b 256 -j 2 all_none.tar.lrz
32.05s user 0.76s system 146% cpu 2751M memory 22.411 total

结果如下:

方法压缩后大小 (字节)
lrzip + bzip360’672’608
lrzip + lzma64’774’202
lrzip + bzip275’685’065

有关与 Turbo-Range-Coder 和 BSC 的进一步基准测试,请查看 powturbo 对 bzip3、bzip2、bsc 等的基准测试 (https://github.com/powturbo/Turbo-Range-Coder)。

免责声明

对于因使用本程序/库而导致的任何数据丢失,无论何种原因造成,本人概不负责。

每次压缩文件都意味着假设压缩文件可以被解压以恢复原始文件。在设计、编码和测试方面付出了巨大努力以确保本程序正确运行。

然而,算法的复杂性,特别是代码中存在概率极低但非零的特殊情况,使得无法排除程序中仍存在错误的可能性。

除非您准备好接受数据可能无法恢复的极小可能性,否则不要使用此程序压缩任何数据。

这并非意味着本程序本质上不可靠。事实上,我非常希望情况相反。Bzip3/libbz3 经过精心构建和广泛测试。

BZip3 的性能 严重 依赖于编译器。x64 Linux clang13 构建通常可以达到高达 17MiB/s 的压缩速度和 23MiB/s 的解压速度 每线程。Windows 和 32 位构建可能明显更慢。

Bzip3 已在以下架构上进行了测试:

  • x86
  • x86_64
  • armv6
  • armv7
  • aarch64
  • ppc64le
  • mips
  • mips64
  • sparc
  • s390x

语料库基准测试

基准测试可视化

更多结果请查看 etc/BENCHMARKS.md。

许可证

以下是组件及其许可证的明细:

  • (运行时)整个代码库:版权 2022-2023, Kamila Szewczyk ([email protected]); LGPL (LICENSE)
  • (运行时)Burrows-Wheeler 变换 (libsais) 和 LZP 代码:2021-2022, Ilya Grebnov ([email protected]); Apache 2.0 (3rdparty/libsais-LICENSE)
  • (编译时)build-aux:版权 2011, Daniel Richard G ([email protected]), 2019, Marc Stevens ([email protected]), 2008, Steven G. Johnson ([email protected]); GPL-3+ 含 AutoConf 例外
  • (编译时)build-aux/ax_check_compile_flag.m4:版权 2008, Guido U. Draheim ([email protected]), 2011, Maarten Bosmans ([email protected]); FSFAP
  • (编译时)build-aux/git-version-gen:版权 2007-2012, Free Software Foundation, Inc; GPLv3
  • (运行时)bz3grep:版权 2003, Thomas Klausner; BSD-2-clause

bzip3 整体仅在 LGPLv3 许可证下授权。它不是在 LGPLv3 和 Apache 2.0 的双许可证下授权。

致谢

  • Ilya Grebnov,感谢他用于 BZip3 中 BWT 构建的 libsais 库以及我用作参考实现来改进自己的 LZP 编码器。
  • Caleb Maclennan,感谢他为 BZip3 配置 autotools 作为对包管理友好的构建系统。
  • Ilya Muravyov,感谢他的公共领域 BWT 后编码器,本项目的衍生品使用了它。

相似文章

OpenZL

Lobsters Hottest

OpenZL 是一个压缩库,能够为特定数据格式生成专门的压缩器,以高速实现高压缩比,适用于数据中心工作负载,如 AI 处理。

GetCompress

Product Hunt

GetCompress 是一个无损媒体压缩工具,无需切换上下文。