2009年3月13日金曜日

Heapyを試す

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク
さきのエントリで名前が出てきたHeapyをへろっと試してみた。
dictを100回ネストと、インスタンスを1100回ネスト、listを1000回ネストしてみた。


In [14]: h.heap()
Out[14]:
Partition of a set of 60943 objects. Total size = 9562944 bytes.
Index Count % Size % Cumulative % Kind (class / dict of class)
0 31276 51 2886304 30 2886304 30 str
1 541 1 1295696 14 4182000 44 dict (no owner)
2 13437 22 1254624 13 5436624 57 tuple
3 204 0 809728 8 6246352 65 guppy.sets.setsc.ImmNodeSet
4 186 0 603552 6 6849904 72 dict of module
5 3628 6 435360 5 7285264 76 function
6 3617 6 405104 4 7690368 80 types.CodeType
7 363 1 326168 3 8016536 84 list
8 342 1 284256 3 8300792 87 dict of class
9 196 0 246848 3 8547640 89 dict of type
In [16]: d = {}

In [17]: for i in range(100):
d = dict(hoge=d)
Out[19]:
Partition of a set of 61155 objects. Total size = 9609792 bytes.
Index Count % Size % Cumulative % Kind (class / dict of class)
0 31284 51 2886704 30 2886704 30 str
1 645 1 1327824 14 4214528 44 dict (no owner)
2 13445 22 1255192 13 5469720 57 tuple
3 204 0 809728 8 6279448 65 guppy.sets.setsc.ImmNodeSet
4 186 0 603552 6 6883000 72 dict of module
5 3628 6 435360 5 7318360 76 function
6 3617 6 405104 4 7723464 80 types.CodeType
7 365 1 326440 3 8049904 84 list
8 342 1 284256 3 8334160 87 dict of class
9 196 0 246848 3 8581008 89 dict of type
In [20]: len(gc.get_objects())
Out[20]: 27920

In [21]: class Hoge:
....: def __init__(self, v):
....: self._v = v
....:
....:

In [22]: x = Hoge(None)

In [23]: for i in range(100):
....: x = Hoge(x)
....:
....:

In [24]: h.heap()
Out[24]:
Partition of a set of 61438 objects. Total size = 9656504 bytes.
Index Count % Size % Cumulative % Kind (class / dict of class)
0 31295 51 2887240 30 2887240 30 str
1 647 1 1330672 14 4217912 44 dict (no owner)
2 13450 22 1255552 13 5473464 57 tuple
3 204 0 809728 8 6283192 65 guppy.sets.setsc.ImmNodeSet
4 186 0 603552 6 6886744 71 dict of module
5 3629 6 435480 5 7322224 76 function
6 3618 6 405216 4 7727440 80 types.CodeType
7 365 1 326440 3 8053880 83 list
8 343 1 284528 3 8338408 86 dict of class
9 196 0 246848 3 8585256 89 dict of type
In [25]: for i in range(1000):
x = Hoge(x)
....:
....:

In [27]: h.heap()
Out[27]:
Partition of a set of 63469 objects. Total size = 10005064 bytes.
Index Count % Size % Cumulative % Kind (class / dict of class)
0 31299 49 2887432 29 2887432 29 str
1 648 1 1331712 13 4219144 42 dict (no owner)
2 13451 21 1255624 13 5474768 55 tuple
3 204 0 809728 8 6284496 63 guppy.sets.setsc.ImmNodeSet
4 186 0 603552 6 6888048 69 dict of module
5 3629 6 435480 4 7323528 73 function
6 3618 6 405216 4 7728744 77 types.CodeType
7 365 1 326440 3 8055184 81 list
8 1101 2 299472 3 8354656 84 dict of __main__.Hoge
9 343 1 284528 3 8639184 86 dict of class
n [32]: for i in range(1000):
....: L = [L]
....:
....:

In [33]: h.heap()
Out[33]:
Partition of a set of 64569 objects. Total size = 10159328 bytes.
Index Count % Size % Cumulative % Kind (class / dict of class)
0 31306 48 2887792 28 2887792 28 str
1 651 1 1337136 13 4224928 42 dict (no owner)
2 13457 21 1256096 12 5481024 54 tuple
3 204 0 809728 8 6290752 62 guppy.sets.setsc.ImmNodeSet
4 186 0 603552 6 6894304 68 dict of module
5 1366 2 462512 5 7356816 72 list
6 3629 6 435480 4 7792296 77 function
7 3618 6 405216 4 8197512 81 types.CodeType
8 1101 2 299472 3 8496984 84 dict of __main__.Hoge
9 343 1 284528 3 8781512 86 dict of class

0 件のコメント: