linux - unix中sort命令的性能

标签 linux unix sorting pipe

我正在为我的公司编写一个自定义的 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/

相关文章:

regex - 使用带点的 sed 在字符串中删除行

python - 为什么base64解码字符串在Python2.7和Linux中不一样

linux - 在 bash 中运行多个进程

unix - linux - useradd : group user1 exists - if you want to add this user to that group, 使用-g

c - 为什么sockaddr_storage 结构定义为它定义的方式?

c++ - 在 C++ 中使用合并排序算法合并文件

linux - 无法让脚本在后台运行

javascript - JQuery复杂类和ID排序

javascript - 在 IE 中,Javascript 数组项未定义

shell - 使用 shell 脚本将值存储在数组中