Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何从 1 亿行 *.gz 文件返回行间隔?
假设我需要从 1500 万到 2000 万的 500 万行?
这是表现最好的选择吗?
zcat myfile.gz|head -20000000|tail -500 real 0m43.106s user 0m43.154s sys 0m9.259s
这是一个完全合理的选择;因为你不知道一行会有多长,所以你基本上必须解压缩并迭代这些行以找出行分隔符的位置。这三个工具都经过了相当程度的优化,因此 I/O 和解压缩时间可能无论如何都会占主导地位。
从理论上讲,推出您自己的解决方案,将所有三个工具组合在一个可执行文件中可能会节省一点(通过降低 IPC 的成本),但节省的成本可能可以忽略不计。