RealTime RealTime::operator +(const RealTime &t) const { if (GetUsec() + t.GetUsec() >= ONE_MILLION) { return RealTime(GetSec() + t.GetSec() + 1, GetUsec() + t.GetUsec() - ONE_MILLION); } else { return RealTime(GetSec() + t.GetSec(), GetUsec() + t.GetUsec()); } }
bool RealTime::operator >(const RealTime &t) const { if (GetSec() > t.GetSec()) return true; if (GetSec() == t.GetSec() && GetUsec() > t.GetUsec()) return true; return false; }
RealTime RealTime::operator +(int msec) const { int usec = GetUsec() + msec * 1000; if (usec >= ONE_MILLION) { return RealTime(GetSec() + usec / ONE_MILLION, usec % ONE_MILLION); } else { return RealTime(GetSec(), usec); } }
RealTime RealTime::operator -(int msec) const { int usec = GetUsec() - msec * 1000; if (usec < 0) { usec = -usec; return RealTime(GetSec() - usec / ONE_MILLION - 1, ONE_MILLION - usec % ONE_MILLION); } else { return RealTime(GetSec(), usec); } }
~Timer() { long long usec = GetUsec() - m_tv; float bw = m_sz / (1.024 * 1.024 * usec); std::cout << m_msg << ": " << usec << " us\t" << bw << " MB/sec" << std::endl; }
Timer(const std::string& msg, size_t sz): m_msg(msg), m_sz(sz) { m_tv = GetUsec(); }
long RealTime::Sub(const RealTime &t) { return (GetSec() - t.GetSec()) * 1000000 + GetUsec() - t.GetUsec(); }
int RealTime::operator -(const RealTime &t) const { return (GetSec() - t.GetSec()) * 1000 + int((GetUsec() - t.GetUsec()) / 1000.0); }