【发布时间】:2018-01-29 16:27:31
【问题描述】:
%timeit 魔法支持在行模式和单元模式下执行。使用单元格模式,通过%%timeit(注意:两个百分号)调用,可用于从测量中排除一些设置代码:
%%timeit [-n<N> -r<R> [-t|-c] -q -p<P> -o] setup_code code code...
但是你如何使用它呢?这给出了一个错误:
>>> %%timeit sleep(0.1); sleep(0.1)
...
UsageError: %%timeit is a cell magic, but the cell body is empty.
Did you mean the line magic %timeit (single %)?
这并不排除基准测试的第一行:
>>> %%timeit
... sleep(0.1)
... sleep(0.1)
...
200 ms ± 17.6 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)
【问题讨论】:
标签: python ipython profiling timing ipython-magic