I just noticed to something very strange. When I use %%timeit -n1 -r1
magic command, to measure the execution time of a block of code in Jupyter lab, python does not keep the value of local variables after the execution of the block!
For instance, if I run a block of code containing the following codes:
for i in range(10):
for j in range(10):
d = i - j
and then run print(d)
in another block, the jupyter will show me the value of d in the last iteration.
But if I run this block of code:
%%timeit -n1 -r1
for in in range(10):
for j in range(10):
d = i - j
and then run print(d)
, the juoyter shows me an error message:
NameError: name 'd' is not defined
What is the explanation behind this strange behaviour?