Time Magics

There are magics for timing execution of code with a similar syntax to the standard ones in Python.


In [ ]:
%time 2**128

You are able to execute few statements in single line.


In [ ]:
%time a = [10,20,30,40,50]; a= a.sum(); a*10;

Time measurement in cell mode


In [ ]:
%%time 
a = [10,20,30,40,50]; 
a= a.sum(); 
a*10;

Function %time provides very basic timing functionality.
Use the timeit magic for more control over the measurement.
Time execution of a Python statement or expression

Usage, in line mode:

%timeit [-n<N> -r<R> -q] statement

or in cell mode:

%%timeit [-n<N> -r<R> -q] code code...

Options:
-n: execute the given statement times in a loop. If this value is not given, a fitting value is chosen.
-r: repeat the loop iteration times and take the best result. Default: 3
-q: Quiet, do not print result.


In [ ]:
%timeit -n10 -r3 sin(100)*cos(123)

In [ ]:
%timeit -r3 sin(100)*cos(123)

In [ ]:
%timeit -r3 -n1 sleep(1000)

In [ ]:
%%timeit -r3 -n10
a = 15;
b = 111;
a * b;