在shell中以不同顺序调用uniq和排序。

问题描述 投票:3回答:3

uniq uniqsort 在shell脚本中调用它们时?我这里说的是时间和空间上的问题。

grep 'somePattern' | uniq | sort

对比

grep 'somePattern' | sort | uniq

在一个140 k行的文本文件上的快速测试显示,第一种方法(获取uniq值然后排序)的速度略有提高(5.5 s vs 5.0 s)。

我不知道如何测量内存使用量,虽然......

现在的问题是:顺序有区别吗?还是取决于grep返回的行数(manyfew duplicates)

optimization shell performance sorting uniq
3个回答
© www.soinside.com 2019 - 2024. All rights reserved.