使用 Apache Commons Compressor 进行缓慢的 LZ4 解压缩

时间:2021-04-28 15:03:27

标签: java lz4 apache-commons-compress

我从第三方接收了一些经过 LZ4 帧压缩的数据。然后我需要解压缩它,我正在使用 Apache Commons Compressor。代码如下:

    int buffersize = 1024;
    InputStream fin = new ByteArrayInputStream(compressed);
    BufferedInputStream in = new BufferedInputStream(fin);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    FramedLZ4CompressorInputStream zIn = new FramedLZ4CompressorInputStream(in);
    final byte[] buffer = new byte[buffersize];
    int n = 0;
    while (-1 != (n = zIn.read(buffer))) {
        out.write(buffer, 0, n);
    }
    out.close();
    zIn.close();

    return out.toByteArray();

这是直接来自教程,但是速度很慢,数据大小为:

将 14411185 字节解压为 31961088 字节

速度为:

解压耗时 7295 毫秒

这给了我 (14411185*8) / (7295/1000) = 15,803,904(15.8MB/秒)的解压速度。这是在 JDK15 64 位、Win10 i7 8 核、32Gb 内存上运行

LZ4 的报价速度为 4530 MB/s(参考 ZStandard 的网页)。这意味着我使用 apache commons 压缩器慢了大约 300 倍。有没有人见过这么差的速度?

请注意,我已经尝试预热 apache commons 压缩器,但没有任何改变。

谢谢。

问候,

尼尔

0 个答案:

没有答案