How to properly measure time of a loop - having issues with global scope I think

Hi, I’m working in IJulia with @time begin to measure how long my code takes.

I have some code that iterates row by row over one input dataframe, merges it with other dataframes that had been assigned to variables earlier on in the same notebook, and for some reason if I run the code with @time for one specific “row”, it works fine, but the minute I put the code in a while or for loop, and try to iterate row by row over the input dataframe, I start getting these errors saying that my previously assigned variables have not been defined.

But the same exact variables its able to reference when there’s no while or for loop.

I know this is probably something to do with scope but I was wondering if someone could help me figure out how to fix

Can you give a minimal example? It’s hard to tell what’s going on here from your description.

1 Like

What you describe sounds like the different scope behaviour in the REPL.
Put all your code into a function and call this.
(or make use of global)

A MWE always helps for us to see if this is really the case.

(I may be wrong because you said IJulia but try the function)

1 Like