Fixed bug causing incorrect time for run all

This commit is contained in:
2020-07-10 00:52:47 -04:00
parent 40ea05ac42
commit 7257a118d4

View File

@@ -147,14 +147,13 @@ void runAll(){
//Run through all valid problem numbers, skipping a few that are in the tooLong vector //Run through all valid problem numbers, skipping a few that are in the tooLong vector
for(unsigned int cnt = 1;cnt < PROBLEM_NUMBERS.size();++cnt){ for(unsigned int cnt = 1;cnt < PROBLEM_NUMBERS.size();++cnt){
unsigned int problemNumber = PROBLEM_NUMBERS[cnt]; unsigned int problemNumber = PROBLEM_NUMBERS[cnt];
double totalTime = 0;
//Get the problem //Get the problem
Problem* problem = getProblem(problemNumber); Problem* problem = getProblem(problemNumber);
//Run the problem the specified number of times //Run the problem the specified number of times
std::cout << problemNumber << ". " << problem->getDescription() << '\n'; std::cout << problemNumber << ". " << problem->getDescription() << '\n';
runProblem(problem, timesToRun); double totalTime = runProblem(problem, timesToRun);
//Print the results //Print the results
std::cout << getBenchmarkResults(problem, totalTime, timesToRun); std::cout << getBenchmarkResults(problem, totalTime, timesToRun);
@@ -194,14 +193,14 @@ double runProblem(Problem* problem, unsigned int timesToRun){
} }
//Prints the benchmark results of a problem //Prints the benchmark results of a problem
std::string getBenchmarkResults(Problem* problem, double totalTime, unsigned int timesRan){ std::string getBenchmarkResults(Problem* problem, double totalTime, unsigned int timesRun){
//Calculate the average run time of the problem //Calculate the average run time of the problem
totalTime /= timesRan; totalTime /= timesRun;
std::string timeResults = mee::Stopwatch::getStr(totalTime); std::string timeResults = mee::Stopwatch::getStr(totalTime);
//Tally the results //Tally the results
std::stringstream results; std::stringstream results;
results << "\n\n" << problem->getString(); results << "\n\n" << problem->getString();
results << "\nIt took an average of " << timeResults << " to run this problem over " << timesRan << " iterations\n\n" << std::endl; results << "\nIt took an average of " << timeResults << " to run this problem over " << timesRun << " iterations\n\n" << std::endl;
return results.str(); return results.str();
} }