123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #include <iostream>
- #include <sys/types.h>
- #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<double>(mTmsTime.tms_utime) / mTicksPerSec;
- double SystemTime = static_cast<double>(mTmsTime.tms_stime) / mTicksPerSec;
- double RealTime = static_cast<double>(mRealTime) / mTicksPerSec;
- cout << "User time = " << UserTime << "s\n";
- cout << "System time = " << SystemTime << "s\n";
- cout << "Real time = " << RealTime << "s\n";
- }
|