Question

When using IPython, it's often convenient to see how long your commands take to run by using the %time magic function. When you use this often enough, you start to wish that you could just get toggle a setting to get this metadata by default whenever you enter a query. Psql lets you do this with \timing. GHCi lets you do this with :set s+. Does IPython let you do this? And if not, why not?

Was it helpful?

Solution

The "ipythonic" way of timing code is using the %timeit or %%timeit magic function (respectively for online, and multi-line code).

These functions provide quite accurate results by running the code multiple times (the exact number is adaptive if not specified).

The global flag you are asking does not exist in ipython. Furthermore, just adding %%timeit to all the cells will not work because global variables are not modified when calling %%timeit. This "feature" is directly inherited from the timeitmodule.

For more info see this ipython issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top