In my IPython console (IPython 6.4.0 with Python 3.6.5, installed under Anaconda 5.2), this works.
%timeit %run sortThis
Be careful of several things. Use the %cd
magic command to make sure your current working directory is the one holding the sortThis
script. Either that, or include the path to the script in your command. Also, if the script prints anything, you could end up with hundreds or thousands of copies of the printing in your console before %timeit
shows its results.
When I had just the command print('Hello, world!')
in the sortThis
script, I got this result:
1.23 ms ± 5.97 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
I'm pretty sure that the first load of the script caused Python saved the compiled version to a .pyc
file and and that file was in my computer's cache. So the stated time averaged all that over many executions, resulting in a small time interval. So don't expect %timeit
to time your first execution of the script--just the average over many consecutive executions.