Eric Arnold wrote:

I'm using win32 gvim70f.  If I use the externan Cygwin grep

grep -i -r vimgrep .

it returns the results in under a second.

:vimgrep vimgrep **

takes about 20 seconds.
Without having looked at the code, let me assume that vimgrep is simply re-using its regular expression
pattern matching code.

I believe that grep itself has several pattern matching algorithms built-in. If one is looking for a straight string, Boyer-Moore is a very good algorithm (it ends up looking at approx O(N/M) usually, where N=qty chars in text, M=qty chars in pattern). Regular expressions will, at best,
usually be about O(N) (worst case is a _lot_ longer).

One can look for multiple words quickly with an Aho-Corasik pattern matcher. Again, they must
be fixed words, no wildcards, etc.

So, unless Bram installed a lot of pattern matching algorithms into ViM just to support :vimgrep, I'm not surprised that grep can be a lot faster. Try both algorithms with a pattern consisting
of a single (non-magic) character and comparing them.

Another point: :vimgrep is often making a list out of the matches, thereby incurring memory
management overhead.

Regards,
Chip Campbell

Reply via email to