Concerning the effectiveness - I sketched a simple test, below. The result on my machine in Windows 7 with VC ++ 2015 - when outputting to the console
cout sync : 3204554 cout async: 3225070 stdout : 1153035
when redirecting to a file
cout sync : 4695 cout async: 4818 stdout : 2334
So, of course, stdout is faster, but at least unsafe ... As for sync_with_stdio(false) - it seems like a myth :)
Source:
#include <vector> #include <string> #include <iostream> #include <iomanip> #include <cstdio> #include <chrono> using namespace std; int main(int argc, const char * argv[]) { const int Count = 10000; vector<int> data; for(int i = 0; i < Count; ++i) data.push_back(rand()); auto start = chrono::high_resolution_clock::now(); for(auto i: data) { printf("%d ",i); } auto stop = chrono::high_resolution_clock::now(); cout << endl; auto printf_time = chrono::duration_cast<chrono::microseconds>(stop-start).count(); start = chrono::high_resolution_clock::now(); for(auto i: data) { cout << i << " "; } stop = chrono::high_resolution_clock::now(); cout << endl; auto iostream_sync_time = chrono::duration_cast<chrono::microseconds>(stop-start).count(); cout.sync_with_stdio(false); start = chrono::high_resolution_clock::now(); for(auto i: data) { cout << i << " "; } stop = chrono::high_resolution_clock::now(); cout << endl; auto iostream_async_time = chrono::duration_cast<chrono::microseconds>(stop-start).count(); cout << "cout sync : " << iostream_sync_time << endl; cout << "cout async: " << iostream_async_time << endl; cout << "stdout : " << printf_time << endl; }
And yet - I just can not understand why the vehicle is linking the issue with C ++ 11. After all, there were no changes in this area.
std::ios::failureno longer fromstd::exception, but fromstd::system_error. There are other changes. The question is just asked to find out the opinion of more experienced comrades - sys_dev