#include #include #include "stopwatch.hpp" using namespace std; StopWatch::StopWatch(): mRounds(0) { } void StopWatch::start() { mStartTime.getCurrentTime(); } void StopWatch::stop() { mStopTime.getCurrentTime(); mStopTime.subtract(mStartTime); mStopTime.print(); } void StopWatch::stopRound() { mStopTime.getCurrentTime(); Time TotalDiff = mStopTime - mStartTime; Time RoundDiff = mStopTime - mLastStopTime; mLastStopTime = mStopTime; cout << "Round " << mRounds++ <<":\n"; RoundDiff.print(); cout << "Total:" << "\n"; TotalDiff.print(); } Time& Time::subtract(const Time& Subtrahent) { mTmsTime.tms_utime -= Subtrahent.mTmsTime.tms_utime; mTmsTime.tms_stime -= Subtrahent.mTmsTime.tms_stime; mRealTime -= Subtrahent.mRealTime; return *this; } Time Time::operator-(const Time& Subtrahent) const { Time Result(*this); return Result.subtract(Subtrahent); } void Time::print() { double UserTime = static_cast(mTmsTime.tms_utime) / mTicksPerSec; double SystemTime = static_cast(mTmsTime.tms_stime) / mTicksPerSec; double RealTime = static_cast(mRealTime) / mTicksPerSec; cout << "User time = " << UserTime << "s\n"; cout << "System time = " << SystemTime << "s\n"; cout << "Real time = " << RealTime << "s\n"; }