On 3/19/12 6:13 PM, Geir Hauge wrote: > 2012/3/19 Chet Ramey <chet.ra...@case.edu>: >> I will look at optimizing that function, but it's always going to take time >> to plow through 300K when you have to split it into words. (There's not >> actually any word splitting of consequence happening with your second >> example using the pipeline.) > > Letting compgen do the command substitution speeds it up considerably > > $ TIMEFORMAT=%R > $ time compgen -W "`seq 1 500000`" 1794 >/dev/null > 175.253 > $ time compgen -W '`seq 1 500000`' 1794 >/dev/null > 2.347
That's an excellent suggestion. Instead of splitting into 500000 words and then expanding each one, you do one word expansion that ends up being split into 500000 words. The command substitution is more efficiently performed by the second invocation. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/