Skip to content

bosswissam/pysize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Measure size of memory object in python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages