On 3/15/12 3:38 PM, Richard Neill wrote:
> Dear Bob,
>
> Thanks for your explanation. I do understand what is going on and why. But
> my point was that compgen has an implicit internal "grep" that is much less
> efficient than actual grep. Why is the performance of compgen's
> sorting/filtering algorithm so much worse than grep's ?
> Both of them start with a large list, and filter it to a small one.
Only by the most general of similarities. In the first case, bash reads
300K through a pipe and stores it into a large string. It then splits
the string into 50,000 words, expands each word using the shell word
expansions, then tests the expanded words for matches against a
particular string. Grep reads a series of very short lines from stdin,
a line at a time, and matches each against a regexp.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU [email protected] http://cnswww.cns.cwru.edu/~chet/