#include #include #include #include #include "StopWatchT.h" using namespace std; using namespace std::chrono; double DoTest(long int iterations); int main() { double result; StopWatchT watch; watch.Start(); // you must use this or the -O* option will remove all code result = DoTest(200'000'000); watch.Stop(); if (result == 0) { cout << "It is 0" << endl; } cout << "That took " << endl; watch.PrintTimes(); cout << "In Different Units" << endl; for(int i =0; i < 6; i++) { TimeUnitT unit = static_cast(i); cout << "\t" << watch.TimeInUnit(unit) << " " << TimeUnitTToString(unit) << endl; } cout << endl << endl << endl; watch.Start(); result += DoTest(100'000'000); watch.Stop(); if (result == 0) { cout << "It is 0" << endl; } cout << "The time is now " << endl; cout << "\t" << watch.TimeInUnit(TimeUnitT::SECOND) << " " << TimeUnitTToString(TimeUnitT::SECOND) << endl; cout << endl << endl << endl; watch.Continue(); result += DoTest(100'000'000); watch.Stop(); if (result == 0) { cout << "It is 0" << endl; } cout << "The time is now " << endl; cout << "\t" << watch.TimeInUnit(TimeUnitT::SECOND) << " " << TimeUnitTToString(TimeUnitT::SECOND) << endl; cout << endl << endl; for(int i = 0; i < 10; i++) { watch.Start(); result += DoTest(100'000'000); watch.Stop(); if (result == 0) { cout << "It is 0" << endl; } cout << "Iteration " << i << "\t" << watch.TimeInUnit(TimeUnitT::SECOND) << " " << TimeUnitTToString(TimeUnitT::SECOND) << endl; } return 0; } double DoTest(long int iterations) { double d{0}, e{0}; for(long int i =0; i < iterations; i++) { d+= sqrt (static_cast(i)); e+= sqrt (static_cast(i)); } return d+e; }