我从第三方收到了一些经过 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 压缩器,但没有任何改变。
谢谢。
问候,
尼尔