Use timeit
modular , You can test a piece of code or function n The total time of the times .
See Python timeit Usage of
To be in ipython It can only be used under the following circumstances (Jupyter Notebook Of course, it can be used ,pycharm Inside python So is the environment jupyter Notebook Of )
%time You can measure the execution time of a line of code
%timeit You can measure the time of multiple executions of a line of code
See python %time %timeit