Back to: 23. Multi Core Programming and Threads
// testingProgram.cpp // compile with // c++ testingProgram.cpp -o myTest -std=c++11 -pthread // execute with // ./myTest #include #include #include class SimpleTimer{ private: int64_t timerStart; int64_t timerEnd; int64_t timerInProgress; public: SimpleTimer(const int64_t & =0); void start(); void end(); double getTime(); }; SimpleTimer::SimpleTimer(const int64_t & _inProgress){ timerInProgress=_inProgress; if(timerInProgress==1){ timerStart=std::chrono::high_resolution_clock::now().time_since_epoch().count(); } } void SimpleTimer::start(){ timerInProgress=1; timerStart=std::chrono::high_resolution_clock::now().time_since_epoch().count(); } void SimpleTimer::end(){ timerInProgress=2; timerEnd=std::chrono::high_resolution_clock::now().time_since_epoch().count(); } double SimpleTimer::getTime(){ if(timerInProgress!=2){ return -1.0; } double fR= double(timerEnd)-double(timerStart); fR/= 1000000000.0; return fR; } long powerFunction(long a, long b, long p){ long res=1; long i=0; while(i < b){ res*=a; res%=p; ++i; } return res; } void executeOnOneThread(long* alpha, long* beta, long* gamma, long p, long m, long start, long end){ while(start