#include #include "StopWatchT.h" #include #include #include using namespace std; using namespace std::chrono; const vector UNITS{"hour", "minute","second", "milisecond","microsecond","nanosecond"}; string TimeUnitTToString(TimeUnitT u) { return UNITS[static_cast(u)]; } void StopWatchT::Start(){ start = high_resolution_clock::now(); diff = diff.zero(); } void StopWatchT::Stop(){ end = high_resolution_clock::now(); diff += end - start; } void StopWatchT::Continue(){ start = high_resolution_clock::now(); } void StopWatchT::PrintTimes(){ cout << duration{diff}.count() << " ns" << endl; cout << duration{diff}.count() << " us" << endl; cout << duration{diff}.count() << " ms" << endl; cout << duration>{diff}.count() << " s" << endl; cout << duration>{diff}.count() << " m" << endl; cout << duration>{diff}.count() << " h" << endl; } double StopWatchT::TimeInUnit(TimeUnitT u){ switch (u) { case TimeUnitT::HOUR: return duration>{diff}.count(); case TimeUnitT::MINUTE: return duration>{diff}.count(); case TimeUnitT::SECOND: return duration>{diff}.count(); case TimeUnitT::MILLISECOND: return duration{diff}.count(); case TimeUnitT::MICROSECOND: return duration{diff}.count(); case TimeUnitT::NANOSECOND: return duration{diff}.count(); default: return 0; } }