V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
dbow
V2EX  ›  Python

分享一个程序,用于获取 python 内置对象的内存占用。

  •  
  •   dbow ·
    maliubiao · 2014-06-23 21:04:33 +08:00 · 4214 次点击
    这是一个创建于 3612 天前的主题,其中的信息可能已经有所发展或是发生改变。
    python有gc平时不用关心内存, 大量处理数据的时候,要优化内存占用得知道这个
    代码: http://pastebin.ubuntu.com/7690309/
    输出示例:
    type basicsize itemsize mro
    <type 'NoneType'> 16 0 (<type 'NoneType'>, <type 'object'>)
    <type 'int'> 24 0 (<type 'int'>, <type 'object'>)
    <type 'long'> 24 4 (<type 'long'>, <type 'object'>)
    <type 'float'> 24 0 (<type 'float'>, <type 'object'>)
    <type 'bool'> 24 0 (<type 'bool'>, <type 'int'>, <type 'object'>)
    <type 'str'> 37 1 (<type 'str'>, <type 'basestring'>, <type 'object'>)
    <type 'unicode'> 48 0 (<type 'unicode'>, <type 'basestring'>, <type 'object'>)
    <type 'str'> 37 1 (<type 'str'>, <type 'basestring'>, <type 'object'>)
    <type 'complex'> 32 0 (<type 'complex'>, <type 'object'>)
    <type 'dict'> 248 0 (<type 'dict'>, <type 'object'>)
    <type 'tuple'> 24 8 (<type 'tuple'>, <type 'object'>)
    <type 'list'> 40 0 (<type 'list'>, <type 'object'>)
    <type 'set'> 200 0 (<type 'set'>, <type 'object'>)
    <type 'frozenset'> 200 0 (<type 'frozenset'>, <type 'object'>)
    ......
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1959 人在线   最高记录 6547   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:23 · PVG 00:23 · LAX 09:23 · JFK 12:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.