Subscribe to the RSS Feed

 

Onedot.nl Services

Now including a free temporary website!

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


Comments

  1. 247 days ago

    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.

  2. 247 days ago

    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

  3. 247 days ago

    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.

  4. 247 days ago

    Light green Says:

    Why light green on white ? hard to read the web site.. :(

Leave a Comment

Add your comment. Preview then Submit.


Hidden


Textile Help