Earlier quoted context omitted.
All of your examples work in memory.
Even working in memory, there are different efficiencies for different methods. Awk includes an asort() function which can sort an array, such that it would be possible to create a similar process entirely within awk to the sort | uniq -c pipeline: #!/usr/bin/gawk -f { x[NR] = $1 } END { rc = asort(x) j=0 for(i in x) { if( x[i] "" == x[i-1] "" ) freq[j]++ else { j++ elem[j] = x[i] freq[j] = 1 } } for(j in elem) { pri…
sort | uniq -c takes .017s (fastest out of a few runs)
the awk command I used above takes .013s
A trivial implementation I have in go takes .08s
Additionally, using this 'protos' file which is 1,000,000 lines of tcp,udp,icmp:
$ time (sort protos|uniq -c)
5915 icmp
332003 tcp
662082 udp
real 0m0.232s
user 0m0.739s
sys 0m0.100s
$ # fixed to count 'lines' and not the first column, which makes it faster.
$ time awk '{lines[$0]++} END {for (l in lines) printf("%s %d\n", l, lines[l])}'
so yes, I do test my assumptions.