【问题标题】:memit and timeit at the same timememit 和 timeit 同时
【发布时间】:2015-09-16 18:18:49
【问题描述】:

我可以同时 %memit%timeit 一个 IPython 单元格吗?
如果出现以下情况,它将运行多少次?

%memit -r 3
%timeit -r 2
my_awesome_function()

【问题讨论】:

    标签: python profiling ipython


    【解决方案1】:

    在 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)
    

    哪个输出:

    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
    

    【讨论】:

      猜你喜欢
      • 2013-10-06
      • 2020-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      • 2013-01-17
      • 2013-10-01
      • 2018-01-04
      相关资源
      最近更新 更多