Giter VIP home page Giter VIP logo

remember-me's Introduction

Remember Me

Build Status

RememberMe is a handy tool for memory problems in Python. It computes the total memory usage of Python objects.

RememberMe is a replacement for sys.getsizeof

sys.getsizeof is almost confusing in Python:

import sys
a = [1, 2, 3]
b = [a, a, a]
print(sys.getsizeof(a) == sys.getsizeof(b))  # Can you believe the result is `True`?

While rememberme gives you a clear idea how large an object is.

from rememberme import memory
a = [1, 2, 3]
b = [a, a, a]
print(memory(a))  # 172 bytes!
print(memory(b))  # 260 bytes!

Installation

pip install rememberme

More features

Check out memory usage in the current frame:

from rememberme import memory
def foo():
    a = [1, 2, 3]
    b = [a, a, a]
    print(memory())
foo()  # 260 bytes. Note `a` is included in `b`.

Check out top memory consumers:

from rememberme import top
def foo():
    a = [1, 2, 3]
    b = [a, a, a]
    mem_top = top()  # with no args, check current frame
    print(mem_top[0])  # `b` and its memory usage
    print(mem_top[1])  # `a` and its memory usage

Even pretty print the result!

from rememberme import mem_print
def foo():
    a = [1, 2, 3]
    b = [a, a, a]
    mem_print(b)
foo()

Output:

                           ┌int (28.0B)
             ┌list (172.0B)┼int (28.0B)
             │             └int (28.0B)
             │             ┌int (28.0B)
list (260.0B)┼list (172.0B)┼int (28.0B)
             │             └int (28.0B)
             │             ┌int (28.0B)
             └list (172.0B)┼int (28.0B)
                           └int (28.0B)

Known issues and limitations

  • For better performance (and making better sense), the global dict, as well as modules, are not included in the memory usage of any objects.
  • We essentially relies on tp_traverse to traverse the object graph. For C extensions, memory usage might be underestimated under various circumstances. For the most common numpy.ndarray, a specific procedure is defined to probe the memory usage correctly, but no correctness is guaranteed for other C extensions, which may have undetectable momery leaks within themselves.

remember-me's People

Contributors

liwt31 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

zapersea jab

remember-me's Issues

Question

import  sys
a = [1,2,3]
b = [a,a,a]
print(sys.getsizeof(a)== sys.getsizeof(b))

My result is False?

Why the name "remember-me"?

Hi, I hit the library in one answer and it seems like a good candidate to determine the size of the Python objects. Also, I see a lot of people have this need but it'đ really hard to find the library. My question is, why the name "remember-me" maybe with a different name it would be more searchable and useful for more people 😃 Or maybe just add a note to the readme why it is called like this :)

Ou, and it seems I am the 1st creating the issue here. Yaay 🎉

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.