Contents of the function run well when timed alone, but not when they are in a loop inside the function

Given your code I can only speculate that you are referencing (non constant) global variables, which is a well known performance pitfall in Julia. Maybe it would be helpful to compile a complete MWE?

1 Like