3 ms·
I'm going to agree with you here. 99% of the time this UUOC stuff is just premature optimization. If it gets the job done it does not matter if it wastes a fe
by Amadou 13y ago
I'm going to agree with you here. 99% of the time this UUOC stuff is just premature optimization. If it gets the job done it does not matter if it wastes a few milliseconds.
- joshbaptiste 13y agoThe problem is when I see UUOC use in fairly large scripts. I've seen load averages shoot through the roof due to numerous separate commands that are being run causing needless context switching as each set of commands is being run per line of a large datafile.
- dpcx 13y agoFixing it at that point is no longer a "premature optimization"...
- e12e 13y agoWait, what? You mean like this?: cat somefile |while read line do echo $line|cat -|pipe... done Because otherwise I can't see how a pipeline would be started for each line of a datafile ?
- adestefan 13y agoIt's more common to see this issues with something like this: for f in *; do cat $f | ... done Now make that a directory with thousands of files or a script digs down through through the tree.
- e12e 13y agoBut it's not really the "cat" that's the problem here, is it?
- cnvogel 13y agoSure it's possible without running a subprocess, just open the file on some other filedescriptor. exec 5<words.txt while read line <&5 ; do echo "line read: $line" done exec <&5-
- Amadou 13y ago(1) Like dpcx said, dealing with that isn't premature optimization. (2) Be careful about load averages, lots of people don't understand them. It just means the number of processes ready to run over a period of time. It is entirely possible to have a very high load average with a very low cpu utilization. A bunch of little processes that hop on and off the run queue really quickly because they only have a little bit of work to do at a time can kick the load average up way higher than a single self-contained process doing the same amount of work with the same amount of total cpu utilization. The single process wins on context switches, but modern cpus cache those in hardware so its barely a win any more.
- deleted 13y ago[deleted]