// faire test 10000 + lamba + 1...coreCount #include #include #include "triskeleDealThreads.hpp" #include "TestThread.hpp" using namespace std; using namespace boost::chrono; using namespace triskele; using namespace otb; using namespace otb::triskele; inline void fDirect (const DimImg &nbItem, const vector &global) { DimImg sum = 0; for (DimImg x = 0; x < nbItem; ++x) sum += global[x]; } template inline void fLambda (DimImg &nbItem, const FunctId &functId/* functId (id) */) { for (DimImg x = 0; x < nbItem; ++x) functId (x); } template inline void fThread (double &inDuration, const DimImg &nbItem, const FunctId &functId/* functId (id) */) { // One thread #if INTEL_TBB_THREAD using namespace tbb; #pragma warning(disable: 588) parallel_for (size_t (0), size_t (1), [&nbItem, &functId, &inDuration] (size_t idCopyValInThread) { auto start = high_resolution_clock::now (); for (DimImg x = 0; x < nbItem; ++x) functId (x); auto end = high_resolution_clock::now (); inDuration = duration_cast > (end-start).count (); }); #else /* BOOST thread */ std::vector tasks; for (unsigned int idCopyValInThread = 0; idCopyValInThread < 1; ++idCopyValInThread) { tasks.push_back (boost::thread ([/*no ref!!!*/idCopyValInThread, &nbItem, &functId, &inDuration] () { auto start = high_resolution_clock::now (); for (DimImg x = 0; x < nbItem; ++x) functId (x); auto end = high_resolution_clock::now (); inDuration += duration_cast > (end-start).count (); })); } for (unsigned int i = 0; i < 1; ++i) tasks[i].join (); #endif } void TestThread::testDeal () { DimImg nbItem = global.size (); double inDuration = 0; // XXX direct auto startDirect = high_resolution_clock::now (); fDirect (nbItem, global); // XXX lambda auto startLamba = high_resolution_clock::now (); DimImg sum = 0; fLambda (nbItem, [this, &sum] (const DimImg &x) { sum += global [x]; }); // XXX thread auto startThread = high_resolution_clock::now (); sum = 0; fThread (inDuration, nbItem, [this, &sum] (const DimImg &x) { sum += global [x]; }); // XXX n direct // XXX n lambda // XXX n thread auto end = high_resolution_clock::now (); addTime (directDealStats, duration_cast > (startLamba-startDirect).count ()); addTime (lambdaDealStats, duration_cast > (startThread-startLamba).count ()); addTime (threadDealStats, duration_cast > (end-startThread).count ()); addTime (inThreadDealStats, inDuration); }