您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

使用IPython测量(最大)内存使用量-类似于timeit但要注意

使用IPython测量(最大)内存使用量-类似于timeit但要注意

实际上,它已经存在,作为实用名称memory_profiler包的一部分:

In [2]: %memit np.zeros(1e7)
maximum of 3: 76.402344 MB per loop

更多信息请参见https://github.com/pythonprofilers/memory_profiler#ipython- integration

编辑:要使用此功能,您首先需要将其作为IPython扩展加载:

%load_ext memory_profiler

为了使IPython在启动时始终加载memory_profiler扩展,请将其添加c.InteractiveShellApp.extensions配置文件的列表中ipython_config.py

$ grep -C2 c.InteractiveShellApp.extensions ~/.ipython/profile_default/ipython_config.py
 # A list of dotted module names of IPython extensions to load.
 #
 c.InteractiveShellApp.extensions = [
   'autoreload',
   'memory_profiler',
python 2022/1/1 18:48:22 有408人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶