Something I’ve only just noticed, but I find it interesting. If it’s already known to you, then be happy. :-)
$ time grep -i 'closing' error_log | wc -l
real 0m2.144
user 0m2.139s
sys 0m0.011s
The above is with the default grep, using ‘-i’ to search case insensitive.
$ time grep -iP 'closing' error_log | wc -l
real 0m0.104s
user 0m0.095s
sys 0m0.012s
The above uses -P, or the Perl Regular Expressions. In this example, that’s 20x faster than regular grep! You loose that advantage as soon as you search case sensitive.
The real reason isn’t that Perl regex is magically fast, though. A case-insensitive grep -i is slow in a UTF-8 locale because it has to do multibyte case-folding for every byte; -P happened to skip that slow path. The cleaner, portable fix is to drop the locale instead:
$ time LC_ALL=C grep -i 'closing' error_log | wc -l
That gives you the same speedup as -P without relying on it, since grep -P is officially marked “highly experimental” in the manual and may warn on unimplemented features. So enjoy the trick, but don’t go alias grep='grep -P' across the board.