4 ms·
I've encountered this in command-line programs as well. Print statements take a non-zero amount of time and depending on the language, can be quite slow, so for
by headcanon 10y ago
I've encountered this in command-line programs as well. Print statements take a non-zero amount of time and depending on the language, can be quite slow, so for an otherwise-fast operation in a loop, if it prints a line every time then it can contribute significantly to the overall speed of the program. Removing the print statements in some cases can speed up the code by an order of magnitude.
- dijit 10y agoquiet reminder that writing to file descriptors is blocking. STDERR and STDOUT are file descriptors.
- orf 10y agoYep, and this is very noticeable if your using windows and select any portion of the terminal. All stdout/stderr is blocked. I had a call when one of our services stopped responding. Took a while to figure out there was a tiny one-character selection in the power shell.
- deleted 10y ago[deleted]
- colemickens 10y agoI often wonder if its why it took them over a decade (two decades?) to enable QuickEdit mode by default. Sometimes I'll wonder why something is taking so long and realize that my palm accidentally caused a quickedit selection in cmd.exe.
- thaumasiotes 10y agoMaybe so, but, as pointed out elsewhere in the thread, printing to stdout is much, much, much, much slower than printing to a file. The fact that stdout is a file descriptor can only explain a vanishingly small quantity of the time cost of using it.
- goldenkek 10y agoblocking. blocking. blocking. blocking. rtfm
- thaumasiotes 10y agoAgain, the problem is not that writing to file descriptors is blocking. The problem is that writing to the screen is very slow. Writing to a file is just as blocking, but you'll block for much less time, because writing to a file is not slow.
- anthk 10y ago2>&1>/dev/null
- arjie 10y agoIt's a combination of many things. You're probably writing to a file buffered, but terminal writes are generally unbuffered. In addition, I had a terminal setup once that just did a poor job of displaying text (line wrapping was slow, perhaps) and programs that would write out to stdout would be slow.
- majewsky 10y ago> printing to stdout is much, much, much, much slower than printing to a file False dichotomy. stdout can very well be a file. What you mean is that printing to a terminal is slower than to a file.
- thaumasiotes 10y agoTrue enough.
- anthk 10y agoAvoid verbose flags on tar.
- jmiserez 10y agorsync as well, especially the progress bars.