Domanda

Given that there's some overhead in writing to the console, would redirecting stderr and stdout to /dev/null save this overhead and be faster? I needed the statements to help debug and provide status updates for my application, but now that I am deploying it to an embedded system, there will be no one to read these console outputs. I figured an easy way to save this overhead is to just have the application redirect the outputs to /dev/null.

Also, does writing to the console still have a penalty if no one is connected to the console? (I'm assuming yes).

Thanks for the help.

È stato utile?

Soluzione 2

Created a simple C program and spat out "THIS IS AN ERROR MESSAGE\n" to stderr on my Linux laptop. The message was printed in a loop 100,000 times.

With no redirection, the program took 6,104,888 microseconds. Running with redirection to /dev/null resulted in the program being completed in 23,747 microseconds.

Therefore, the console is really slow, and alot of time can be saved by dumping anything you don't need to /dev/null or (better yet) just not printing it in the first place.

Altri suggerimenti

Yes you will save some penalties writing to /dev/null. Writing to /dev/null is just a call to a function that finally does nothing with your data, so you will finally save at least data location at writing, and some data transfer. Test it with a small program that write to stdout and redirect the output to /dev/null, you will be able to measure.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top