Originally Posted by
Sang-drax
Well, ugly collisions are expected, even if cout is thread safe. The important thing is that the program doesn't crash.
Ah, okay. I must have missed the point then.
Here's the code I used to time your code. I'm running a P4 3Ghz processor with HT.
Code:
#include <iostream>
#include <fstream>
using std::cout;
using std::endl;
#include <sys/timeb.h>
#include "Petter-For.h"
using Petter::For;
#include <boost/lambda/lambda.hpp>
using namespace boost::lambda;
boost::lambda::placeholder1_type i;
int main()
{
std::ofstream outfile("outfile.txt");
cout << "Started..." << endl;
_timeb oldTime, newTime;
_ftime(&oldTime);
For(0,10000, outfile << i << ' ');
_ftime(&newTime);
cout << "Threaded: "
<< ((int)((newTime.time - oldTime.time) * 1000)
+ (newTime.millitm - oldTime.millitm))
<< endl;
_ftime(&oldTime);
for(int i= 0; i < 10000; i++)
outfile << i << '\n';
_ftime(&newTime);
cout << "Not Threaded: "
<< ((int)((newTime.time - oldTime.time) * 1000)
+ (newTime.millitm - oldTime.millitm))
<< endl;
}
Results look like this:
Code:
Started...
Threaded: 125
Not Threaded: 47