首先在 shell 中测试如下命令

1
2
#!/bin/sh
time gzip -d -c risearch_chr1:143971112-143971134:+:FAM72C.out.gz > risearch_chr1:143971112-143971134:+:FAM72C.out
1
0.28s user 0.02s system 99% cpu 0.297 total

然后测试 python

1
2
3
4
5
6
7
8
import gzip
def parse_gzip_py(ris_file):
inf = gzip.open(ris_file, 'rt')
with open("test_py_gz.txt","w") as f:
for line in inf:
f.write(line+"\n")

inf.close()
1
2
%timeit parse_gzip_py("risearch_chr1:143971112-143971134:+:FAM72C.out.gz")
399 ms +/- 1.91 ms per loop

Julia 里面有两个解析 Gzip 的包,分别

GZip.jlCodecZlib.jl

我们分别来测试一下

1
2
3
4
5
6
7
8
9
10
using GZip
function parse_gzip_file(filename::String)
out = open("test_gzipjl.txt", "w")
zips = GZip.open(filename)
while !eof(zips)
line = readline(zips)
println(out, line)
end
close(out)
end
1
2
@time parse_gzip_file("risearch_chr1:143971112-143971134:+:FAM72C.out.gz")
0.388812 seconds

然后是codeczlib,必须用另一个包调用它

1
2
3
4
5
6
7
8
9
10
11
using TranscodingStreams
using CodecZlib

function parse_gzi_trans(filename::String)
out = open("test_trans.txt", "w")
stream = GzipDecompressorStream(open(filename))
for line in eachline(stream)
println(out, line)
end
close(out)
end
1
2
@time parse_gzi_trans("risearch_chr1:143971112-143971134:+:FAM72C.out.gz")
0.280360 seconds

结论:

Julia 语言使用 GZip 包的时候,速度要慢于 shell,快于 python;使用 CodecZlib 的时候,
速度快于 shell 和 python。但是整体时间来看,最快的比最慢的也就快 0.1s,
这也就意味着,即使是要解压 10000 个文件,Julia 也就比 python 快 16 分钟而已。
这个在巨大的解压用时面前,并不算什么。

数据文件可从我的 github 获取
link