I think the synchronization problem is due to the fact that the console is configured by default by default. This means that every time you write the character '\n' , your entire output buffer is sent to the console, which is quite an expensive operation. This is the price you pay for the line immediately appearing on the output.
You can change this default behavior by changing the buffering strategy to full buffering. The consequence is that the output will be sent to the console in chunks that are equal to the size of your buffer, but certain operations will be faster.
Make this call before you first enter the console:
char buf[10000]; setvbuf(stdout, buf, _IOFBF, sizeof(buf));
The time of individual entries should improve, but the result will not appear on the console immediately. This is not very useful for debugging, but time will improve. If you set up a stream that calls fflush(stdout) at regular time intervals, say, once per second, you should get a reasonable balance between the performance of individual records and the delay between your program that writes the output and the time that you can actually see its on the console.
dasblinkenlight Jul 19 '12 at 10:32 2012-07-19 10:32
source share