Problem with stringstream and multithreading
SSTREAM has a patch to vastly improve performance
http://www.dinkumware.com/vc_fixes.html
I've compiled the following test as a console app:
Code:
#include <sstream>
#include <fstream>
#include <ctime>
#include <iostream>
using namespace std;
int main()
{
ofstream out("out.txt");
stringstream ss;
clock_t start,= clock();;
for (int i=0; i<100000; ++i)
ss << "," << i;
ss << endl;
clock_t finish = clock();
cout << finish-start << endl;
out << ss.str();
return 0;
}
With the patch, it takes 1000 ticks on my computer to execute (debug mode). Using the original SSTREAM it takes 37500 ticks (about 40 times longer).
However, using the patched SSTREAM file and setting the compiler option to /MDd (multi thread), rather than the default /MLd (single thread) takes execution time back upto 37500 ticks again.
Why is this happening, and how can I get the multithreaded version to work properly? (I want to do a similar thing in an multi threaded MFC application).
Thanks