C++ does printing to terminal significantly slow down code?

It really depends on how much you are printing.

If your program is printing 50 or more lines per second then I bet output starts to become significant.

Output to a file is definitely much faster than printing to a terminal, though different terminal programs will vary significantly in their speed, depending on how much rendering they are doing and what they use for the rendering api.

I very much doubt there is any significant performance difference for cout vs. ofstream for performance of terminal printing or even output to a file. There might be a very small performance gain if you wrote log lines using fwrite. Ultimately things like cout will call fwrite, so you can get a small improvement by just calling down to that lowest level yourself.

Finally - output streams like cout are faster than error streams like cerr. Cout will do more buffering than cerr, performance can be significantly faster. But it looks like you are using cout already.


Yes, rendering to screen takes longer than writing to file.
In windows its even slower as the program rendering is not the program that is running, so there are constantly messages sent between processes to get it drawn.
I guess its same in linux since virtual terminal is on a different process than the one that is running.


How much of a speed hit you get will depend on several factors. The Windows console, for instance, is notorously slow. ofstream might be slighlty faster than cout, depending on yor libc++ implementation (different buffer sizes, thread synchronization, ...)


It certainly can be. Printing to a terminal involves rendering and other things (non-trivial) and is typically buffered a lot less. The OS and stream implementation can do a lot more buffering and caching with file I/O.