我正在为我的公司编写一个自定义的 Apache 日志解析器,我注意到一个我无法解释的性能问题。我有一个大小为 1.2GB 的文本文件 log.txt。
命令:sort log.txt 比命令:cat log.txt | 慢最多 3 秒排序
有人知道为什么会这样吗?
最佳答案
cat 文件 | sort
是一个 Useless Use of Cat .
The purpose of cat is to concatenate (or "catenate") files. If it's only one file, concatenating it with nothing at all is a waste of time, and costs you a process.
它不应该花更长的时间。您确定您的时间安排正确吗?
请发布输出:
time sort file
和
time cat file | sort
您需要运行几次命令并获得平均值。
关于linux - unix中sort命令的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6225858/