2017-05-02 1 views
0

큰 데이터 세트를 사용하면 메모리 사용에 대해 걱정할 필요가 없습니다. bulit-in 함수, 깔끔한 해킹 또는 널리 사용 가능한 패키지가 주어진 유형의 메모리 사용을 결정합니까?파이썬 형식의 메모리 사용을 어떻게 결정합니까?

현재로서는 얼마나 많은 메모리를 로컬 메모리에 합리적으로로드 할 수 있는지 결정하기 위해 하나의 pandas.timedelta Object 하나가 얼마나 많은 메모리 바이트를 필요로하는지 궁금합니다. 어떤 유형의 메모리 요구 사항을 결정하는 일반적인 방법이 바람직합니다.

답변

1
this can be done by using python memory profiler 
>>> from guppy import hpy; h=hpy() 
>>> h.heap() 
Partition of a set of 48477 objects. Total size = 3265516 bytes. 
Index Count %  Size % Cumulative % Kind (class/dict of class) 
    0 25773 53 1612820 49 1612820 49 str 
    1 11699 24 483960 15 2096780 64 tuple 
    2 174 0 241584 7 2338364 72 dict of module 
    3 3478 7 222592 7 2560956 78 types.CodeType 
    4 3296 7 184576 6 2745532 84 function 
    5 401 1 175112 5 2920644 89 dict of class 
    6 108 0 81888 3 3002532 92 dict (no owner) 
    7 114 0 79632 2 3082164 94 dict of type 
    8 117 0 51336 2 3133500 96 type 
    9 667 1 24012 1 3157512 97 __builtin__.wrapper_descriptor 
<76 more rows. Type e.g. '_.more' to view.> 
>>> h.iso(1,[],{}) 
Partition of a set of 3 objects. Total size = 176 bytes. 
Index Count %  Size % Cumulative % Kind (class/dict of class) 
    0  1 33  136 77  136 77 dict (no owner) 
    1  1 33  28 16  164 93 list 
    2  1 33  12 7  176 100 int 
>>> x=[] 
>>> h.iso(x).sp 
0: h.Root.i0_modules['__main__'].__dict__['x'] 
>>>