Lab 7: Function Optimization

Due March 18

Optimizing, or creating a program which does the same thing in less time or using less memory, is not only the job of the optimization phase of the compiler. For this lab, there's a start file called optimization_lab.cpp in the class examples area. It contains two functions, both of which run slowly. Modify them so that they retain the current functionality, but with greater speed. When you finish, both functions should pass the test cases in main in less than one millisecond.
Once optimized, it should be a lot faster. Here are results from isoptera, no compiler optimization:
seth@isoptera:~ $ ./a.out
Time taken:  0.00023 milliseconds
9227465
Time taken:  0.013305 milliseconds
1
So if your computer is very fast and beats the 1ms standard right out of the gate, you should be looking for a time significantly better than the above. Isoptera has a lot of cores, but the tradeoff on server chips is usually marginal single-thread performance. So I'd guess at least some people in the class will have a computer that can beat the above times.