3

I am aware of using the magic command %timeit in an IPython notebook to time individual functions.

However, I currently need to supply the time required to execute the calculations of an entire IPython notebook. How can I do this?

One option would be to save the IPython notebook as a Python file with extension .py and then run the entire time feature in the command line.

However, I am dealing with several calls of the matplotlib functions and pylab. This make take so long there are runtime errors.

How does one do this?

1 Answer 1

2

You can:

  1. Export the notebook as *.py file.
  2. Create a new notebook.
  3. Copy the whole content of the *.py file into one cell of this notebook.
  4. Time this cell with %%timeit (note the double %) by adding this command in the first line.

You might need to edit the cell content as magic % commands are commented out. Likely that you don't want to measure the time for invoking things like %matplotlib inline. Therefore, moving these magic commands into a separate cell seems sensible.

Sign up to request clarification or add additional context in comments.

3 Comments

there may be an easier way using runipy - but I am not sure if it's already fully compatible with ipython-4.x
@cel runipy looks interesting. Timing notebook_instance.run_notebook() might time all sorts of internal setup code in addition to the algorithms in the notebook. Does it provide explicit timing support?
I don't think so, I guess the results are only accurate if the overhead of runipy is small compared to the notebook execution size.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.