3 ms·
By the way, > "cat myfile | grep foo | awk '...'" […] indeed this is one of the most frequent performance sinks in shell scripts Is it really? I would've thou
by unhammer 13y ago
By the way,
> "cat myfile | grep foo | awk '...'" […] indeed this is one of the most frequent performance sinks in shell scripts
Is it really? I would've thought loops were a more common performance sink. I can't imagine how that useless use of cat has _that_ much of an effect, unless you're running a whole bunch of copies of this script. It looks ugly in the process table and it does not let the real command (here: grep) move back and forth in the file, but I've never noticed performance improvements from removing uuoc's.
- e12e 13y agoTo be fair, there's (probably) two forks too many: awk can do filtering on regular expressions too. Not that I think it really makes much of difference in most cases.
- jzwinck 13y agoMy original phrasing may have been unclear; with the elision you made the thrust becomes quite different. I intended to convey two thoughts: that Useless Use of Cat and other filters is pervasive because it is so easy, and secondly, that spawning tons of unnecessary processes is a common performance waste. The specific example with just three processes (cat, grep, awk) is not such a big deal--the bad cases are when stuff like that happens within loops (but the performance loss is not due to the loops, but rather the spawning).