Speed up grep
After Tobias Klausmann did some research on grep and ack, he later found out that grep is faster after all when using the C locale. Way faster.
The following line in your .bashrc will make sure grep allways uses the C locale, without specifying it everytime or changing your current locale:
alias grep='LC_ALL="C" grep'
Results (won’t work with that line in your .bashrc):
$ time LC_ALL="nl_NL.utf8" grep -iR grep-speed docs/
real 0m53.818s
user 0m52.419s
sys 0m1.349s
$ time LC_ALL="C" grep -iR grep-speed docs/
real 0m0.662s
user 0m0.351s
sys 0m0.311s
Juliano Says:
Could it be faster the second time because the file is already in the buffer? That is, the first grep loaded the file from the disk into memory buffer, therefore took more time. The second one used the contents loaded in the buffer.
bart9h Says:
Juliano, no. That would affect the “real” time, but not the “user” time.
“real” = clock time
“user” = active cpu time running the program code
“sys” = active cpu time running system calls called by the program
rgh Says:
Not in the testing I did. In fact it was faster without setting LC_ALL. My locale is en_AU.UTF-8 (LC_COLLATE is set to ‘C’ though). And yes I did prime the cache before running the tests.
Light green Says:
Why light green on white ? hard to read the web site.. :(