6 ms·
This is because in the first example you are invoking two programs. The first one sort the content of the file, the second count how many lines are equal. Whil
by tuldia 7y ago
This is because in the first example you are invoking two programs. The first one sort the content of the file, the second count how many lines are equal.
While in the awk example it is creating a hash table with all words and incrementing by the key and then printing.
There is no sorting plus printing may be buffered.
- justinsaccount 7y agoThanks for explaining my own comment to me.
- tuldia 7y agoNot explaining, trying to tell that you are comparing apples to oranges and making a conclusion based on that. Also, you don't need to spawn a subshell nor feed sort via stdin in the first example :)
- cperciva 7y agoHe's comparing apples to oranges and reaching the conclusion that... yes, apples and oranges are different things. He's quite aware of this, and even points out the tradeoff -- `sort | uniq -c` still works if your dataset doesn't fit into RAM.
- tuldia 7y agoCounting "words" vs sorting+counting "lines" are a complete different thing. Heck, forget about RAM, the output of both programs don't even match. That awk is pretty efficient and fast is no surprise ;)