X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=WCudaMSE%2FBilatTools_CPP%2Fsrc%2Fcore%2Ftools%2Fcpp%2FChronos.cpp;fp=WCudaMSE%2FBilatTools_CPP%2Fsrc%2Fcore%2Ftools%2Fcpp%2FChronos.cpp;h=0b9457425ff17f3e6c8fa974f662f2164b93edf7;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/BilatTools_CPP/src/core/tools/cpp/Chronos.cpp b/WCudaMSE/BilatTools_CPP/src/core/tools/cpp/Chronos.cpp new file mode 100755 index 0000000..0b94574 --- /dev/null +++ b/WCudaMSE/BilatTools_CPP/src/core/tools/cpp/Chronos.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +#include + +#include "Chronos.h" + +using std::cout; +using std::endl; + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Constructor *| + \*-------------------------------------*/ + +Chronos::Chronos() + { + start(); + } + +Chronos::~Chronos() + { + // rien + } + +/*--------------------------------------*\ + |* Methodes *| + \*-------------------------------------*/ + +void Chronos::start() + { + // cout << "Chronos : start" << endl; + + isRunning = true; + + deltaTime = -1; + timeStart = time(); + } + +double Chronos::stop() + { + //cout << "Chronos : stop" << endl; + + isRunning = false; + + timeStop = time(); + deltaTime = timeStop - timeStart; + + return deltaTime; + } + +double Chronos::getDeltaTime() const + { + if (isRunning) + { + cout << "Chronos : Warning : Stop chrono befor, or use methode timeFlight() instead!" << endl; + return -1; + } + else + { + return deltaTime; + } + } + +double Chronos::timeFlight() const + { + return time() - timeStart; + } + +void Chronos::print(const string& titre) const + { + print(cout, titre); + } + +void Chronos::print(ostream& stream, const string& titre) const + { + double dt; + if (isRunning) + { + dt = timeFlight(); + } + else + { + dt = deltaTime; + } + stream << titre << " " << dt << " (s)" << endl; + } + +double Chronos::time() + { + // return time(NULL); // #include time(NULL) est time_t + // Problem : Sous linux : compte en seconde! + + return omp_get_wtime(); //#include + } + +/*--------------------------------------*\ + |* Friend *| + \*-------------------------------------*/ + +ostream& operator <<(ostream& stream, const Chronos& chrono) // friend + { + chrono.print(stream); + return stream; + } + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ +