I noticed that in any program that I write, the time taken to execute is significantly slower if I do a lot of printing to the monitor (i.e. printf or fprintf (stderr, "...")).
I figured that writing to the disk will be slow, because of the physical limitations of the disk. I'm not sure why printing to the screen should slow the program down significantly.
Writing to a terminal is not exactly fast and is not designed to be fast since usually the only stuff that goes to stdout are pieces of information for the user who is bound by how fast he or she can read stuff.
When you write to the terminal on eg. linux, the following stuff happens (maybe). The kernel is being called between each two consecutive steps:
And those are a lot of steps... Since terminal output is usually only line-buffered, this occurs pretty often.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With