Thank you for your analysis and input.
I have corrected the code to define the variable L as INTENT(IN) as you suggest.
I also updated the code with the version that I am using so that others can run the exact same cases with large arrays and number of iterations. As you say, the difference is significant. When running 100k times, the CPU is quite busy in the first scenario but takes no time in the second:
