4 ms·
> The main reason is that ag prints line numbers when showing matches. Wouldn't it be more accurate to say that ag is slower than grep because it does line-by-
by burntsushi 10y ago
> The main reason is that ag prints line numbers when showing matches.
Wouldn't it be more accurate to say that ag is slower than grep because it does line-by-line searching where as grep does not? What would happen if ag adopted grep's method of searching where it doesn't do line-by-line? Is that possible with PCRE?
I think it would be very interesting to combine the tricks used by grep with the tricks used by ag. I don't think it has been done yet!
- ggreer 10y agoAg doesn't search line-by-line. It's only if a match is found that it goes back and looks for newlines. This optimizes the typical case (most files have no matches) at the expense of the rare case (file contains a match). Also, ag only uses PCRE if the query looks like a regex. Otherwise, it uses Boyer-Moore strstr.
- burntsushi 10y ago> Ag doesn't search line-by-line. Really? Am I misunderstanding this code that very much appears to search line by line? https://github.com/ggreer/the_silver_searcher/blob/master/src/search.c#L113-L121 https://github.com/ggreer/the_silver_searcher/blob/master/sr... GNU grep never does "throw line into buffer and then search it." GNU grep just searches the entire buffer at once.
- ggreer 10y agoYou didn't check to see what value opts.multiline has. It's initialized to TRUE in src/options.c. It's only set to FALSE if a user passes the undocumented --nomultiline option to ag. Default behavior with a regex query is https://github.com/ggreer/the_silver_searcher/blob/master/src/search.c#L92-L111 https://github.com/ggreer/the_silver_searcher/blob/master/sr...
- burntsushi 10y agoAh excellent, thank you for fixing my understanding. :-)