title: C++ getting console app in windows to print as fast as in linux
body: <p>This code:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;chrono&gt;
  #include &lt;functional&gt;
  #include &lt;time.h&gt;
  
  int main() {
      time_t b4 = time(NULL);
      for (int i = 0; i &lt; 50000; i++)
          std::cout &lt;&lt; i &lt;&lt; &quot; &quot;;
      std::cout &lt;&lt; std::endl;
      time_t a4 = time(NULL);
      std::cout &lt;&lt; &quot;Time taken is &quot; &lt;&lt; difftime(a4, b4);
      getchar();
  }
  </code></pre>
  <p>in Windows when compiled/built/run with Visual Studio with commands:</p>
  <pre><code>CL.exe /c /Zi /nologo /W3 /WX- /diagnostics:column /sdl /O2 /Oi /GL /D _MBCS /Gm- /EHsc /MD /GS /Gy /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /FA /Fa&quot;x64\Release\\&quot; /Fo&quot;x64\Release\\&quot; /Fd&quot;x64\Release\vc142.pdb&quot; /Gd /TP /FC /errorReport:prompt ..\src\console_printf.cpp
           console_printf.cpp
         Link:
  link.exe /ERRORREPORT:PROMPT /OUT:&quot;Release\windows.exe&quot; /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:&quot;level='asInvoker' uiAccess='false'&quot; /manifest:embed /DEBUG:FULL /PDB:&quot;Release\windows.pdb&quot; /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG:incremental /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:&quot;Release\windows.lib&quot; /MACHINE:X64 x64\Release\console_printf.obj
  </code></pre>
  <p>finally prints (after printing <code>... 49998 49999</code>)</p>
  <pre><code>Time taken is 15
  </code></pre>
  <p>The same code when compiled/built/run on Linux with:</p>
  <pre><code>g++    -c -O2 -MMD -MP -MF &quot;build/Release/GNU-Linux/_ext/511e4115/console_printf.o.d&quot; -o build/Release/GNU-Linux/_ext/511e4115/console_printf.o ../src/console_printf.cpp
  mkdir -p dist/Release/GNU-Linux
  </code></pre>
  <p>finally prints (after printing <code>... 49998 49999</code>)</p>
  <pre><code>Time taken is 1
  </code></pre>
  <p>That is, console/terminal printing in Linux is just much faster. Both tests were with optimizations turned on in release mode. Although tests were done on two separate machines (one running Windows/Visual Studio, the other running Linux), the computing powers of both are comparable.</p>
  <p>Is there a way to get Windows console printing as fast as Linux? I run a numerically intensive/iterative code which periodically displays progress on the console and I am now worried that unnecessarily Windows console printing might be messing up with the recorded time for no fault of the algorithm but because Windows console printing is unwittingly the bottleneck.</p>