比起稍微麻烦的import time
strat_time
end_time
,jupyter notebook自带magic函数,非常良心了 :)
%%time
运行一次cell的代码花费的时间
1 | %%time |
Wall time: 2.03 ms
%time
运行一次当前行所花费的时间
1 | import numpy as np |
Wall time: 2.99 ms
%timeit
执行一行语句100,000次(默认情况下),然后给出运行最快3次的平均值
1 | import numpy as np |
21 µs ± 406 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)