In both of these you work on datalocal
, but then return data
, which is presumably a global variable. You also access n
, which is a global.
I suggest you restart Julia, get rid of all globals in your code, they are a curse, don’t use them until you are more experienced, if ever.
Then you will get errors if you make mistakes like that again.
Furthemore, you are also timing the generation of your data, by calling rand
, which probably takes more time than the loop. Use rand
outside your function, and pass the data in as an argument.