new file: makefile
[GalaxyCodeBases.git] / python / lib / pysize / README.md
blobbc7836ac7b84ea86aac51c02820f71982da2a9e7
1 [![Build Status](https://travis-ci.org/bosswissam/pysize.svg?branch=master)](https://travis-ci.org/bosswissam/pysize)
3 # pysize
5 Use to quickly measure the size of your python objects. Supports:
6 * Measuring the size of self-referential objects
7 * No double-counting for repeated objects in a collection
8 * Python v2/v3
10 <https://github.com/bosswissam/pysize>
12 # Examples:
13 ```python
14 >>> class Test(object):
15 >>>    pass
16 >>> from pysize import get_size
17 >>> z = Test()
18 >>> get_size(z)
19 344
20 >>> y = [z] * 10000
21 >>> get_size(y)
22 80416
23 >>> z.l = ["test"*100]
24 >>> get_size(z)
25 899
26 >>> get_size(y)
27 80971
28 ```
30 To measure the size of `properties`, call `pysize.get_size` on the full list
31 of the object's members minus overhead and unwanted memberes:
32 ```python
33 import pysize
34 class Ping(object):
35     @property
36     def ping(self):
37         return 'pong'
39 class B(Ping):
40     @property
41     def marko(self):
42         return 'polo'
44 obj = B()
46 to_measure = [getattr(obj, prop) for prop in dir(obj)\
47               if prop not in dir(Ping)] # Exclude inherited attrs
48 empty_list_size = pysize.get_size([])
49 pysize.get_size(to_measure) - empty_list_size - 8 * len(to_measure)
50 ```
52 # License
53 [MIT](LICENSE.txt)