提交 0c39028d 编写于 作者: A Amador Pahim 提交者: Cleber Rosa

DataSize: define __slot__

For small classes, like this one, with known attributes, using dict
wastes a lot of RAM. Defining __slots__ as a list will save a lot of
memory, while improving the performance a bit.

Before this patch:

>>> timeit.timeit('data_structures.DataSize("1M").b',
                  setup='from avocado.utils import data_structures',
                  number=1000000)
>>> 1.1383171081542969

After this patch:

>>> timeit.timeit('data_structures.DataSize("1M").b',
                  setup='from avocado.utils import data_structures',
                  number=1000000)
>>> 1.1071600914001465
Signed-off-by: NAmador Pahim <apahim@redhat.com>
上级 970d850a
......@@ -266,6 +266,7 @@ class DataSize(object):
('m', 1048576), # 2**20
('g', 1073741824), # 2**30
('t', 1099511627776)]) # 2**40
__slots__ = ['_value', '_unit']
def __init__(self, data):
try:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册