I figured I'd present some benchmarks I did because I think it gives some nice examples of the wrong tool for the job. Most of these are from answers on StackOverflow.
Command | Language | Time |
---|---|---|
perl -pe 's/\\e\\[?.*?[\\@-~]//g' |
Perl | 1.921 ms |
strip-ansi |
JavaScript | 113.6 ms |
sed -r "s/[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" |
C | 1.470 ms |
python3 py/strip-ansi.py |
Python | 30.76 ms |
ac -s |
ATS | 962.1 μs |
ansifilter |
C++ | 1.707 ms |
You can see source for this benchmark here. A few brief remarks:
People like JavaScript and Python, but they're wholly unsuitable for systems programming. For perspective, once we've used
strip-ansi
twice, we would have been better off compilingac
from scratch.Writing an ANSI filter with C++ is probably not worth it.
Perl impressed me. It was pleasantly laconic and faster than I expected.
ATS is kind of insane.