O'Reilly logo
  • Mrinali Gupta thinks this is interesting:

%time for _ in range(10): my_arr2 = my_arr * 2


Cover of Python for Data Analysis, 2nd Edition



Time execution of a Python statement or expression.

The CPU and wall clock times are printed, and the value of the expression (if any) is returned. Note that under Win32, system time is always reported as 0, since it can not be measured.

This function can be used both as a line and cell magic:

In line mode you can time a single-line statement (though multiple ones can be chained with using semicolons). In cell mode, you can time the cell body (a directly following statement raises an error). This function provides very basic timing functionality. Use the timeit magic for more control over the measurement.