I have tried to test if there was an overhead in using a subroutine compared to not doing so. It was my impression that for small functions etc. the compiler would automatically inline the functions having the meaning that there was no overhead in using a subroutine call or function. However I have made a test example that shows otherwise (or perhaps I am not using the right compiler settings). The test is this (see also attached source):
Var1 = Var1 + 1.5
Var2 = Var2 + 1.5
Var20 = Var20 + 1.5
Where MySubroutine performs the same calculations as below. The code that is not placed in a subroutine only takes approximately 50% of the time for the code placed in a subroutine.
I have tried to use /Ob2, /Qinline-forceinline /Qipo and other settings, however the difference in time consumption remains.
Is this general behaviour and the lesson to learn do not place code in subroutines if you want fastest code or am I doing something wrong?
I am using Intel(R) Visual Fortran Compiler XE 13.0.0.089 [IA-32]