The %timeit magic command in Jupyter notebooks and the timeit module in regular Python scripts return the average execution time of the code being timed, along with other information such as the standard deviation and the number of loops.
Here's an example output from %timeit:
1.45 µs ± 55.6 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each) |
And here's an example output from timeit.timeit:
3.7156341552734375e-06 |
In both cases, the output is in seconds. The %timeit output includes additional information such as the number of loops and the standard deviation, which can be useful for understanding the reliability of the measurement.
In general, when using %timeit, we want to look at the "mean" value, which is the average execution time, and ignore the "std dev" value, which represents the variability in the measurements. When using timeit.timeit, we just need to look at the output value, which represents the average execution time.
By analyzing the output of %timeit and timeit.timeit, we can get a better understanding of the performance characteristics of our code and identify areas for improvement.