Hi, thanks for your time. I really hope that we will end up saying that Poco has best performance. Even if my test does not illustrate a practical case I would like to understand what may go wrong with it so that we may choose Poco without second thoughts.
I'll try these benchmarks on an other machine to compare (I have a laptop with Intel Core2 Duo T8300 @ 2.40HHz).
Once again what is strange is the behaviour of the CPU usage, it goes up to 100% and then stabilize at 50%).
I measure time with the equivalent of a Poco::StopWatch (not shown in the pieces of code I post).
Here is the code I use for boost:
- Code: Select all
#include _iostream_
#include "boost/thread.hpp"
#define NB_THREADS 50
boost::recursive_mutex mutex;
int iMaxCalls = 1e8;
int iCalls = 0;
int iID = 0;
struct MyRunnable
{
int _iID;
public:
MyRunnable():_iID(iID++) {}
void operator()()
{
for (;;)
{
boost::recursive_mutex::scoped_lock lock(mutex);
++iCalls;
if (iCalls >= iMaxCalls)
{
if (iCalls == iMaxCalls)
std::cout __ "winner is " __ _iID __ std::endl;
break;
}
}
}
};
int main()
{
MyRunnable callback[NB_THREADS];
boost::thread t[NB_THREADS];
for (unsigned int i = 0; i < NB_THREADS; ++i)
{
t[i] = boost::thread(callback[i]);
}
for (unsigned int i = 0; i < NB_THREADS; ++i)
{
t[i].join();
}
return 0;
}