Tuesday, May 05, 2009

GNU grep vs. grep

Open Solaris b111 x64
$ ptime /usr/gnu/bin/grep mysqld 1_4GB_txt_file

real 1:32.055472017
user 1:30.202692546
sys 0.907308690

$ ptime /usr/bin/grep mysqld

real 8.725173958
user 7.621411130
sys 1.056151347


I guess it's due to GNU version being compiled without optimizations... or maybe it is something else. Once I find some time I will try to investigate it.

3 comments:

Razvan said...

is gnu grep actually trying to do case insensitive searches or searching in multiple character sets?

That usually explains such slowdowns.

Knut Anders Hatlen said...

GNU grep is slow in UTF-8 locales, I've heard. What happens if you set LC_ALL=C?

milek said...

Bingo! With LC_ALL=C GNU grep finished in less than 2s while it didn't make any difference for the other grep. Partly it could be due to the fact that GNU grep uses 32KB buffer for reading compared to 8KB... but there's probably more to it.