2

Suppose I have a program that prints a large number of messages to stdout, which takes much time. I wonder whether by redirecting the stdout to /dev/null (so that I see no messages in the screen) we can make the program terminate faster?

[Edit] I tries with small examples. Redirecting stdout to /dev/null does make program terminate earlier.

zell
  • 9,830
  • 10
  • 62
  • 115

1 Answers1

3

Yes. Outputting to the screen requires a lot of painting. Outputting to a file is much faster, because it's running at disc speed. Outputting to /dev/null is faster yet, because the output goes nowhere.

Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
  • When I stored it in avariable and redirect to it I found it slower than expected! `[[ $hide_output ]] && hide=/dev/null` and `./command >>$hide` – Mamdouh Saeed May 17 '23 at 05:16
  • @MamdouhSaeed: Whenever I have a question about speed, I do [*this*](https://stackoverflow.com/a/378024/23771). – Mike Dunlavey May 18 '23 at 12:06