X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fstlplus%2Fsubsystems%2Ftimer.hpp;fp=src%2Fstlplus%2Fsubsystems%2Ftimer.hpp;h=a3ad38d62d4d789bffd63ba51dfb08ad4e111e02;hb=6b0a0d0efafe34d48ab344fca3b479553bd4e62c;hp=0000000000000000000000000000000000000000;hpb=85783316365181491a3e3c0c63659972477cebba;p=chaz%2Fyoink diff --git a/src/stlplus/subsystems/timer.hpp b/src/stlplus/subsystems/timer.hpp new file mode 100644 index 0000000..a3ad38d --- /dev/null +++ b/src/stlplus/subsystems/timer.hpp @@ -0,0 +1,56 @@ +#ifndef STLPLUS_TIMER +#define STLPLUS_TIMER +//////////////////////////////////////////////////////////////////////////////// + +// Author: Andy Rushton +// Copyright: (c) Southampton University 1999-2004 +// (c) Andy Rushton 2004-2009 +// License: BSD License, see ../docs/license.html + +// A CPU timer encapsulated as a class. Measures the CPU time used since its +// construction and allows this cumulative time to be reported at any time. + +//////////////////////////////////////////////////////////////////////////////// +#include "subsystems_fixes.hpp" +#include +#include +#include + +namespace stlplus +{ + + //////////////////////////////////////////////////////////////////////////////// + + class timer + { + private: + clock_t m_clock; + time_t m_time; + + public: + // constructor resets the timer to zero + timer(void); + ~timer(void); + + // reset the timer to zero without destroying it + void reset(void); + + // get the elapsed time in seconds, expressed as a float + float elapsed(void) const; + // get the CPU time in seconds, expressed as a float + float cpu(void) const; + + // get a printable string representing the elapsed time and CPU time + std::string text(void) const; + }; + + //////////////////////////////////////////////////////////////////////////////// + + // print the elapsed time and CPU time using the same representation as the text method + std::ostream& operator << (std::ostream&, const timer&); + + //////////////////////////////////////////////////////////////////////////////// + +} // end namespace stlplus + +#endif