I wanted to compare the speeds of printf
and cout
in C++ using this code for cout
:
#include
int main
It Depends on if you're expected output has to be in order or not. And if you're mixing C-style or other output using the output stream. You do not want to ALWAYS turn off synchronization.
You DO NOT want to turn it off when.
You are mixing Cout with other stream output functions. Like, scanf/printf, gets/puts, getchar/putchar ... ) with C++-style IO (cin/cout ... )[1]
You are using threads with output that you want good output. "Concurrently accessing synchronized streams (i.e., streams for which this function returns true) never introduces data races: characters are read/written individually, although with no further guarantees on its order between threads. This may result in interleaved characters between threads unless proper synchronization of entire operations is enforced by the program."[1]
Other wise it is generally fine to Turn Off the synchronization.
also see: http://en.cppreference.com/w/cpp/io/ios_base/sync_with_stdio