Coder Social home page Coder Social logo

pysize's Introduction

Build Status

pysize

Use to quickly measure the size of your python objects. Supports:

  • Measuring the size of self-referential objects
  • No double-counting for repeated objects in a collection
  • Python v2/v3

Examples:

>>> class Test(object):
>>>    pass
>>> from pysize import get_size
>>> z = Test()
>>> get_size(z)
344
>>> y = [z] * 10000
>>> get_size(y)
80416
>>> z.l = ["test"*100]
>>> get_size(z)
899
>>> get_size(y)
80971

To measure the size of properties, call pysize.get_size on the full list of the object's members minus overhead and unwanted memberes:

import pysize
class Ping(object):
    @property
    def ping(self):
        return 'pong'

class B(Ping):
    @property
    def marko(self):
        return 'polo'

obj = B()

to_measure = [getattr(obj, prop) for prop in dir(obj)\
              if prop not in dir(Ping)] # Exclude inherited attrs
empty_list_size = pysize.get_size([])
pysize.get_size(to_measure) - empty_list_size - 8 * len(to_measure)

License

MIT

pysize's People

Contributors

bosswissam avatar kmouratidis avatar livinthelookingglass avatar mylifeisshan avatar painyeph avatar

Watchers

 avatar

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.