X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fstlplus%2Fsubsystems%2Ftimer.cpp;fp=src%2Fstlplus%2Fsubsystems%2Ftimer.cpp;h=9faac0fea6a86f5b8ba865402628267a9688b764;hb=6b0a0d0efafe34d48ab344fca3b479553bd4e62c;hp=0000000000000000000000000000000000000000;hpb=85783316365181491a3e3c0c63659972477cebba;p=chaz%2Fyoink diff --git a/src/stlplus/subsystems/timer.cpp b/src/stlplus/subsystems/timer.cpp new file mode 100644 index 0000000..9faac0f --- /dev/null +++ b/src/stlplus/subsystems/timer.cpp @@ -0,0 +1,59 @@ +//////////////////////////////////////////////////////////////////////////////// + +// Author: Andy Rushton +// Copyright: (c) Southampton University 1999-2004 +// (c) Andy Rushton 2004-2009 +// License: BSD License, see ../docs/license.html + +//////////////////////////////////////////////////////////////////////////////// +#include "timer.hpp" +#include "dprintf.hpp" +#include "time.hpp" + +//////////////////////////////////////////////////////////////////////////////// + +namespace stlplus +{ + +//////////////////////////////////////////////////////////////////////////////// + + timer::timer(void) + { + reset(); + } + + timer::~timer(void) + { + } + + void timer::reset(void) + { + m_clock = clock(); + m_time = time(0); + } + + float timer::cpu(void) const + { + return ((float)(clock() - m_clock)) / ((float)CLOCKS_PER_SEC); + } + + float timer::elapsed(void) const + { + return ((float)(time(0) - m_time)); + } + + std::string timer::text(void) const + { + return dformat("%4.2fs CPU, %s elapsed", cpu(), delaytime_string(time(0)-m_time).c_str()); + } + +//////////////////////////////////////////////////////////////////////////////// + + std::ostream& operator << (std::ostream& str, const timer& t) + { + return str << t.text(); + } + +//////////////////////////////////////////////////////////////////////////////// + +} // end namespace stlplus