Skip to main content

and the winner is...

Ah, benchmarks - what else would we spend our CPU cycles on anyway? Quite a long time ago I was surprised to see that awk was so much slower than grep. This was a long time ago and I don't remember all the details, but there was sort involved too, and it was GNU/grep vs. Solaris/awk, IIRC. Anyway, here's what I did just now:

# ls -lhgo du.all; wc -l du.all 
 -rw-r--r--    1     2.2M Jan  7 17:26 du.all
          23773 du.all

# time sort -n du.all | grep -v /home > /dev/null 
real	0m8.939s
user	0m8.920s
sys	0m0.010s

# time grep -v /home du.all | sort -n > /dev/null 
real	0m25.694s
user	0m25.670s
sys	0m0.010s

# time awk '!/\/home/' du.all | sort -n > /dev/null 
real	0m0.622s
user	0m0.620s
sys	0m0.010s
Yes, the sort(1) is not even relvant here, it's really grep(1) taking so long. There's a --mmap switch to grep, promising better performance and sometimes coredumps, neither of both happened. This was done with GNU sort-4.5.3, GNU Awk 3.1.1, GNU grep 2.5.1. Oh, yeah - these may have been "current" versions back in ~2002 :)