First profile.
Second, turn up optimizations levels on you compiler.
Thirdly, replace your for loop with multiplication / algebra. For example, the linea+=N
is the fundamental basis for multiplication (repetitive addition), and the loop can be replaced by:a += j * N; N -= j;
Replacing the loop will speed up your program (if your compiler hasn’t already replaced the loop).
Printing the assembly language for the function will show how the compiler applied optimizations.
Edit 1:
Less code means a faster build time as well. I don’t know if time difference in building is measurable.
solved Reducing Run Time C or C++ [closed]