I always forget how I should time little parts of my python code when I'm trying to optimize it, so I put it here so that I can just search for it later.
There's a bunch of timing functions in python: Some use various different clocks, but the Stack Exchange wisdom makes me want to use the timeit module.
.. codeblock:: python
from timeit import default_timer as timer
t_0 = timer()
# here's some code
b = 2 + 2
t_elapsed = timer() - t_0
print('Elapsed time = {t:4.4f} seconds.'.format(t=t_elapsed))