Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is console output so slow?

So I have noticed this while using a few differnt languages on Windows XP, Vista and 7. If you dump a couple thousand lines a second to the console window it generally has a negative impact on the performance of the system. Computer are fast, and always faster, and the console looks like just some text on a back ground. Where is the bottle neck?

like image 496
QueueHammer Avatar asked Sep 13 '11 15:09

QueueHammer


People also ask

Why is console WriteLine slow?

Console. WriteLine is backed by SyncTextWriter which uses a global lock to prevent multiple threads from writing partial lines. This is a major bottleneck that forces all threads to wait for each other to finish the write.

Why is writing stdout slow?

When we are directly writing outputs to our terminal, each writing operation is being done “synchronously”, which means our programs waits for the “write” to complete before it continues to the next commands. Each time our programs writes something to stdout , we are met with this delay.

Is writing to file faster than printing?

Writing to the console is faster, but if the write operation is all that's performed, then a program writing to a file will probably finish first.


1 Answers

printf etc has to go from your process with some sort of IPC to the Console window process (csrss or conhost) The console can also be shared with several processes so there is also some synchronization and buffering going on.

like image 145
Anders Avatar answered Oct 25 '22 19:10

Anders