Reputation: 964
I am writing a custom apache log parser for my company and I noticed a performance issue that I can't explain. I have a text file log.txt with size 1.2GB.
The command: sort log.txt is up to 3 sec slower than the command: cat log.txt | sort
Does anybody know why this is happening?
Upvotes: 3
Views: 1663
Reputation: 274758
cat file | sort
is a 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.
It shouldn't take longer. Are you sure your timings are right?
Please post the output of:
time sort file
and
time cat file | sort
You need to run the commands a few times and get the average.
Upvotes: 4
Reputation: 7438
Instead of worrying about the performance of sort
instead you should change your logging:
Also, are you sure cat is reading the entire file? It may have a read buffer etc.
Upvotes: 1