//------------------------------------------------------------------------------
// Name: fibonacciTimer
//------------------------------------------------------------------------------
std::vector<Stats> fibonacciTimer(size_t nthNumber)
{
std::vector<Stats> stats;
Stats Iteration;
Stats Recursion;
Iteration.type = "Iteration";
Recursion.type = "Recursion";
size_t IterationCount{};
size_t RecursionCount{};
auto timeStartIteration = std::chrono::high_resolution_clock::now();
for (size_t i = 0, IterationCount = nthNumber; i <= nthNumber; i++, IterationCount--)
{
Iteration.values.push_back(fibonacciIteration(IterationCount));if (i % 5 == 0)
{
cout << "\n " << Iteration.type << " " << std::setw(2) << IterationCount << "'th value is: ";
cout << std::setw(6) << Iteration.values[i];
}
}
auto timeStopIteration = std::chrono::high_resolution_clock::now();
long_type durationIteration = std::chrono::duration_cast<std::chrono::microseconds>(timeStopIteration - timeStartIteration).count();
Iteration.microsec = durationIteration;
Iteration.millisec = durationIteration/1000;
Iteration.nanosec = durationIteration*1000;
Iteration.sec = durationIteration/1000000; //Convert to double somehow
stats.push_back(Iteration);
cout << "\n";
cout << "The duration of this task took: " << Iteration.microsec << " microseconds." << endl;
cout << "The duration of this task took: " << Iteration.millisec << " milliseconds." << endl;
cout << "The duration of this task took: " << Iteration.nanosec << " nanoseconds." << endl;
cout << "The duration of this task took: " << Iteration.sec << " seconds." << endl; //Convert to double somehow?
for (size_t i = 0; i < stats.size(); i++)
{
cout << stats[i].values[i] << " " << endl;
}
When I run this, I only get the highest value but twice?:
=====================
===== MAIN MENU =====
1. Measure
2. Timer - Test only
2. Print - Test only
4. Exit
=====================
=====================
Make your choice:1
Choose your number:16
Iteration 16'th value is: 987
Iteration 11'th value is: 89
Iteration 6'th value is: 8
Iteration 1'th value is: 1
The duration of this task took: 6523 microseconds.
The duration of this task took: 6 milliseconds.
The duration of this task took: 6523000 nanoseconds.
The duration of this task took: 0 seconds.
987
987