Skip to content

Instantly share code, notes, and snippets.

@gbishop
Created September 30, 2016 22:26
Show Gist options
  • Save gbishop/5be81922d7521ce3e829565e28d71e0d to your computer and use it in GitHub Desktop.
Save gbishop/5be81922d7521ce3e829565e28d71e0d to your computer and use it in GitHub Desktop.
A script to time running Jupyter notebooks
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor
import sys
import time
notebook_filename = sys.argv[1]
t0 = time.time()
with open(notebook_filename) as f:
nb = nbformat.read(f, as_version=4)
t1 = time.time()
ep = ExecutePreprocessor(timeout=1, kernel_name='python3')
t2 = time.time()
ep.preprocess(nb, {'metadata': {'path': 'notebooks/'}})
t3 = time.time()
with open('executed_notebook.ipynb', 'wt') as f:
nbformat.write(nb, f)
t4 = time.time()
print(t1-t0, t2-t1, t3-t2, t4-t3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment