MBZ*_*MBZ 5 python profiling ipython
我可以同时%memit和%timeit一个 IPython 单元格吗?
在下面的情况下它会运行多少次?
%memit -r 3
%timeit -r 2
my_awesome_function()
Run Code Online (Sandbox Code Playgroud)
在 Jupyter 中尝试了一些组合,最终%%time在单元级别和%memit行级别上使用:
%%time
d = 64
nb = 1000000
nq = 10000
%memit xb = np.random.random((nb, d))
%memit xq = np.random.random((nq, d))
time.sleep(5)
Run Code Online (Sandbox Code Playgroud)
其输出:
peak memory: 1252.40 MiB, increment: 457.10 MiB
peak memory: 797.77 MiB, increment: 2.48 MiB
CPU times: user 866 ms, sys: 230 ms, total: 1.1 s
Wall time: 6.34 s
Run Code Online (Sandbox Code Playgroud)