The magic command %time produces the time it takes to execute a given code segment (statement) to the output cell in Jupyter Notebook. I would like this to be appended on to a specified file instead.
My objective is to find the runtime of an algorithm in different settings. I am able to automate the parameters of the algorithm, although not able to store the output of the %time (and %timeit) magic command in a file for further processing.
Is this possible?
%timeit(but not%time) has a-ooption which makes it return an object, so you can dores = %timeit -o foo(). Then you can get the numbers from res and write them to a file however you wish. For more flexibility, use the timeit module in the standard library.