For-loop efficiency: merging loops
问题 I have always had the idea that reducing the number of iterations is the way to making programs more efficient. Since I never really confirmed that, I set out to test this. I made the following C++ program that measures the time of two different functions: The first function does a single large loop and uses a set of variables. The second function does multiple equally large loops, but a single loop per variable. Complete test code: #include <iostream> #include <chrono> using namespace std;