There is another program I use for editing that is older than ed. It is written in asm. I think it may actually be faster than sed (and sed is faster than AWK, Lua, Perl, Python, etc.) 1.spt: ; x = " - baz" ; y = " - elephant" ;a a = input :f(end) ; output = a ; a ? x :s(d)f(a) ;d output = y ; :(a) ;end spitbol 1.spt
Depends on the awk implementation and the task. However even gnu awk (gawk) is very fast and mawk is astonishing.
Here is a simple example: count the lines, words, and characters in a 65MB text file (10 copies of a novel stuck together).
Testing on Ubuntu GNU/linux 16.10 reporting middle of three tries:
export LANG=ASCII # avoid differences due to unicode
$ time -p wc big10.txt
1284570 10956950 64886660 big10.txt
real 0.29
user 0.28
sys 0.01
$ time -p gawk '{l+=1; w+=NF; c+=length($0)+1} END {print l, w, c}' big10.txt
1284570 10956950 64886660
real 0.55
user 0.53
sys 0.01
Not bad, gawk is less than twice as slow as wc which is the standard tool for this. $ time -p mawk '{l+=1; w+=NF; c+=length($0)+1} END {print l, w, c}' big10.txt
1284570 10956950 64886660
real 0.35
user 0.33
sys 0.01
But mawk is only 20% slower than wc. For a script!Just for a check, even python is not terrible at this:
#!/usr/bin/python
import sys
l, w, c = 0, 0, 0
for line in file(sys.argv[1], "rb"):
l += 1
w += len(line.split())
c += len(line)
print l, w, c
$ time -p ./wc.py big10.txt
1284570 10956950 64886660
real 0.87
user 0.86
sys 0.01
About 3 times slower than wc and mawk.