%timeit is a Jupyter/IPython command for repeatedly executing one line of code and reporting its mean execution time and observed variation. It automatically adjusts the number of loops: very fast code runs many times, while slower code runs fewer. section 12.10
Use the command with these practical rules:
- Write the timed expression on the same line as %timeit; add parentheses when calling a function. section 12.10
- Wrap multiline code in a function, or use %%timeit to time an entire cell. section 12.10
- Compare equivalent pandas operations such as loc, query, isin, and eval while remembering that timings vary between runs. section 12.10
Compare filtering strategies
After loading a parking-ticket DataFrame, time equivalent filters for New York, New Jersey, and Connecticut with loc, query, or isin. Extend the comparison by adding plate type, color, curb distance, and vehicle make conditions. section 12.10
