- 论坛徽章:
- 0
|
统计一个文件行数的最简单方法是什么?
Maybe it's off the topic, I just did a performance test on above methods with no blank line filtering. Just as I expected, wc is the fastest.
time perl -ne 'print $. if eof' tt
3466212
real 0m23.510s
user 0m7.120s
sys 0m1.950s
time perl -ne 'print $. if eof' tt
3466212
real 0m21.308s
user 0m6.660s
sys 0m2.000s
time awk 'END{print NR}' tt
3466212
real 0m22.699s
user 0m3.520s
sys 0m2.420s
time awk 'END{print NR}' tt
3466212
real 0m21.341s
user 0m3.810s
sys 0m2.240s
time wc -l tt
3466212 tt
real 0m18.756s
user 0m0.900s
sys 0m2.300s
time wc -l tt
3466212 tt
real 0m17.333s
user 0m1.120s
sys 0m2.150s
time nl tt|tail -n1
3466212 xxxx
real 1m2.507s
user 0m49.000s
sys 0m5.270s |
|