I'm trying to capture the resulting object of IPython Notebook magic function. Specifically %timeit
So the following code...
import time
def say_hello(n):
time.sleep(n)
print "hello"
t = %timeit say_hello(5)
Prints to stdout:
1 loops, best of 3: 5 s per loop
However, I'd like to capture the result of %timeit say_hello(5)
in the variable t
.
A resulting object called TimeitResult
is generated by %timeit
, but I can't figure out how to access it from within a Notebook.
I'd like a cleaner solution than having to manually capture stdout using sys.stdout
tricks (this code will be part of a presentation so I'm trying to keep it as straight forward as possible). Anyone have any ideas?