Capture the result of an IPython magic function

后端 未结 3 444
时光取名叫无心
时光取名叫无心 2021-01-17 11:54

I\'m trying to capture the resulting object of IPython Notebook magic function. Specifically %timeit

So the following code...

import tim         


        
3条回答
  •  不思量自难忘°
    2021-01-17 12:52

    An example of consuming the TimeItResult output:

    myarray = (3,2,1)
    sorttime = %timeit -n1 -r3 -o myarray.sort() 
    print(sorttime.best)
    

    Look here for the other TimeItResult attributes: https://ipython.org/ipython-doc/2/api/generated/IPython.core.magics.execution.html

提交回复
热议问题