当前位置: 首页>>代码示例>>Python>>正文


Python asizeof.asizeof方法代码示例

本文整理汇总了Python中pympler.asizeof.asizeof方法的典型用法代码示例。如果您正苦于以下问题:Python asizeof.asizeof方法的具体用法?Python asizeof.asizeof怎么用?Python asizeof.asizeof使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pympler.asizeof的用法示例。


在下文中一共展示了asizeof.asizeof方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_collection_sizes

# 需要导入模块: from pympler import asizeof [as 别名]
# 或者: from pympler.asizeof import asizeof [as 别名]
def get_collection_sizes(obj, collections: Optional[Tuple]=None,
                         get_only_non_empty=False):
    """
    Iterates over `collections` of the gives object and gives its byte size
    and number of items in collection
    """
    from pympler import asizeof
    collections = collections or (list, dict, set, deque, abc.Sized)
    if not isinstance(collections, tuple):
        collections = tuple(collections)

    result = []
    for attr_name in dir(obj):
        attr = getattr(obj, attr_name)
        if isinstance(attr, collections) and (
                not get_only_non_empty or len(attr) > 0):
            result.append(
                (attr_name, len(attr), asizeof.asizeof(attr, detail=1)))
    return result 
开发者ID:hyperledger,项目名称:indy-plenum,代码行数:21,代码来源:perf_util.py

示例2: displayMemoryUsage

# 需要导入模块: from pympler import asizeof [as 别名]
# 或者: from pympler.asizeof import asizeof [as 别名]
def displayMemoryUsage(self, timeDescription):
        r"""
        Print out some information to stdout about the memory usage of ARMI.

        Makes use of the asizeof utility.

        Useful when the debugMem setting is set to True.

        Turn these on as appropriate to find all your problems.
        """
        runLog.important(
            "----- Memory Usage Report at {} -----".format(timeDescription)
        )
        self._printFullMemoryBreakdown(
            startsWith="", reportSize=self.cs["debugMemSize"]
        )
        self._reactorAssemblyTrackingBreakdown()
        runLog.important(
            "----- End Memory Usage Report at {} -----".format(timeDescription)
        ) 
开发者ID:terrapower,项目名称:armi,代码行数:22,代码来源:memoryProfiler.py

示例3: __init__

# 需要导入模块: from pympler import asizeof [as 别名]
# 或者: from pympler.asizeof import asizeof [as 别名]
def __init__(self, instance, resolution_level=0, trace=False):
        """
        Create a weak reference for 'instance' to observe an object but which
        won't prevent its deletion (which is monitored by the finalize
        callback). The size of the object is recorded in 'snapshots' as
        (timestamp, size) tuples.
        """
        self.ref = weakref_ref(instance, self.finalize)
        self.id = id(instance)
        self.repr = ''
        self.name = str(instance.__class__)
        self.birth = _get_time()
        self.death = None
        self._resolution_level = resolution_level
        self.trace = None

        if trace:
            self._save_trace()

        initial_size = asizeof.basicsize(instance) or 0
        size = asizeof.Asized(initial_size, initial_size)
        self.snapshots = [(self.birth, size)] 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:24,代码来源:classtracker.py

示例4: __store_stats

# 需要导入模块: from pympler import asizeof [as 别名]
# 或者: from pympler.asizeof import asizeof [as 别名]
def __store_stats(self):

        st_wr = open(self.__project_path + TornadoDic.get_short_names(self.learner.LEARNER_NAME).lower() + ".txt", "w")

        lrn_error_rate = PredictionEvaluator.calculate_error_rate(self.learner.get_global_confusion_matrix())
        lrn_mem = asizeof.asizeof(self.learner, limit=20)
        lrn_runtime = self.learner.get_total_running_time()

        stats = self.learner.LEARNER_NAME + "\n\t" + \
                "Classifier Error-rate: " + "%0.2f" % (100 * lrn_error_rate) + "%" + "\n\t" + \
                "Classifier Memory Usage (bytes): " + "%0.2f" % lrn_mem + "\n\t" + \
                "Classifier Runtime (ms): " + "%0.2f" % lrn_runtime

        print(stats)

        st_wr.write(stats)
        st_wr.close() 
开发者ID:alipsgh,项目名称:tornado,代码行数:19,代码来源:prequential.py

示例5: get_memory_usage

# 需要导入模块: from pympler import asizeof [as 别名]
# 或者: from pympler.asizeof import asizeof [as 别名]
def get_memory_usage(obj, get_collections_memory_usage=False,
                     get_only_non_empty=False):
    result = []
    from pympler import asizeof
    result.append(asizeof.asizeof(obj))
    if get_collections_memory_usage:
        result.append(
            get_collection_sizes(
                obj, get_only_non_empty=get_only_non_empty))
    return result 
开发者ID:hyperledger,项目名称:indy-plenum,代码行数:12,代码来源:perf_util.py

示例6: compute_size

# 需要导入模块: from pympler import asizeof [as 别名]
# 或者: from pympler.asizeof import asizeof [as 别名]
def compute_size(obj):
    return asizeof.asizeof(obj) 
开发者ID:fridiculous,项目名称:estimators,代码行数:4,代码来源:factories.py

示例7: set_object

# 需要导入模块: from pympler import asizeof [as 别名]
# 或者: from pympler.asizeof import asizeof [as 别名]
def set_object(self, value):
        if value is not None:
            object_hash = self.compute_hash(value)
            self.object_property = value
            self._hash = object_hash
            self.file_name = object_hash
            self.byte_size = asizeof.asizeof(value) 
开发者ID:fridiculous,项目名称:estimators,代码行数:9,代码来源:database.py

示例8: add

# 需要导入模块: from pympler import asizeof [as 别名]
# 或者: from pympler.asizeof import asizeof [as 别名]
def add(self, item):
        itemId = id(item)
        if itemId in self.ids:
            return False

        self.ids.add(itemId)
        if self.reportSize:
            try:
                self.memSize += asizeof(item)
            except:
                self.memSize = float("nan")
        self.count += 1
        return True 
开发者ID:terrapower,项目名称:armi,代码行数:15,代码来源:memoryProfiler.py

示例9: calcSize

# 需要导入模块: from pympler import asizeof [as 别名]
# 或者: from pympler.asizeof import asizeof [as 别名]
def calcSize(self, obj):
        tempAttrs = {}
        try:
            for attrName in self.excludedAttributes:
                if hasattr(obj, attrName):
                    tempAttrs[attrName] = getattr(obj, attrName, None)
                    setattr(obj, attrName, None)
            self.sizes.append(asizeof(obj) / (1024.0 ** 2))
            self._breakdownAttributeSizes(obj)
        finally:
            for attrName, attrObj in tempAttrs.items():
                setattr(obj, attrName, attrObj) 
开发者ID:terrapower,项目名称:armi,代码行数:14,代码来源:memoryProfiler.py

示例10: get_obj_referents

# 需要导入模块: from pympler import asizeof [as 别名]
# 或者: from pympler.asizeof import asizeof [as 别名]
def get_obj_referents(oid):
    referents = {}
    obj = get_obj(oid)
    if type(obj) is dict:
        named_objects = asizeof.named_refs(obj)
    else:
        refs = asizeof._getreferents(obj)
        named_objects = [(repr(type(x)), x) for x in refs]
    for name, o in named_objects:
        referents[name] = (get_ref(o), type(o).__name__, safe_repr(o, clip=48), asizeof.asizeof(o))
    return dict(referents=referents) 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:13,代码来源:web.py

示例11: test_slots_being_used

# 需要导入模块: from pympler import asizeof [as 别名]
# 或者: from pympler.asizeof import asizeof [as 别名]
def test_slots_being_used():
    """
    The class is really using __slots__.
    """
    non_slot_instance = C1(x=1, y="test")
    slot_instance = C1Slots(x=1, y="test")

    assert "__dict__" not in dir(slot_instance)
    assert "__slots__" in dir(slot_instance)

    assert "__dict__" in dir(non_slot_instance)
    assert "__slots__" not in dir(non_slot_instance)

    assert set(["__weakref__", "x", "y"]) == set(slot_instance.__slots__)

    if has_pympler:
        assert asizeof(slot_instance) < asizeof(non_slot_instance)

    non_slot_instance.t = "test"
    with pytest.raises(AttributeError):
        slot_instance.t = "test"

    assert 1 == non_slot_instance.method()
    assert 1 == slot_instance.method()

    assert attr.fields(C1Slots) == attr.fields(C1)
    assert attr.asdict(slot_instance) == attr.asdict(non_slot_instance) 
开发者ID:python-attrs,项目名称:attrs,代码行数:29,代码来源:test_slots.py

示例12: test_inheritance_from_slots

# 需要导入模块: from pympler import asizeof [as 别名]
# 或者: from pympler.asizeof import asizeof [as 别名]
def test_inheritance_from_slots():
    """
    Inheriting from an attrs slotted class works.
    """

    @attr.s(slots=True, hash=True)
    class C2Slots(C1Slots):
        z = attr.ib()

    @attr.s(slots=True, hash=True)
    class C2(C1):
        z = attr.ib()

    c2 = C2Slots(x=1, y=2, z="test")
    assert 1 == c2.x
    assert 2 == c2.y
    assert "test" == c2.z

    assert set(["z"]) == set(C2Slots.__slots__)

    assert 1 == c2.method()
    assert "clsmethod" == c2.classmethod()
    assert "staticmethod" == c2.staticmethod()

    with pytest.raises(AttributeError):
        c2.t = "test"

    non_slot_instance = C2(x=1, y=2, z="test")
    if has_pympler:
        assert asizeof(c2) < asizeof(non_slot_instance)

    c3 = C2Slots(x=1, y=3, z="test")
    assert c3 > c2
    c2_ = C2Slots(x=1, y=2, z="test")
    assert c2 == c2_

    assert "C2Slots(x=1, y=2, z='test')" == repr(c2)

    hash(c2)  # Just to assert it doesn't raise.

    assert {"x": 1, "y": 2, "z": "test"} == attr.asdict(c2) 
开发者ID:python-attrs,项目名称:attrs,代码行数:43,代码来源:test_slots.py

示例13: calculate_emr

# 需要导入模块: from pympler import asizeof [as 别名]
# 或者: from pympler.asizeof import asizeof [as 别名]
def calculate_emr(learners, error_weight=1, memory_weight=1, runtime_weight=1, lb=1, ub=10):

        learners_names = []
        learners_errors = []
        learners_runtime = []
        learners_memory_usages = []
        learners_emr_scores = []

        for learner in learners:
            learners_names.append(learner.LEARNER_NAME.title())
            learners_errors.append(PredictionEvaluator.calculate(TornadoDic.ERROR_RATE, learner.get_confusion_matrix()))
            learners_runtime.append(learner.get_total_running_time())
            if memory_weight != -1:
                learners_memory_usages.append(asizeof.asizeof(learner))
            else:
                learners_memory_usages.append(0)

        if len(learners) != 1:
            err_min, err_max = LearnersScoreCalculator.get_min_max(learners_errors)
            run_min, run_max = LearnersScoreCalculator.get_min_max(learners_runtime)
            mem_min, mem_max = LearnersScoreCalculator.get_min_max(learners_memory_usages)

            for i in range(0, len(learners_names)):
                error = LearnersScoreCalculator.scale(learners_errors[i], err_min, err_max, lb, ub)
                runtime = LearnersScoreCalculator.scale(learners_runtime[i], run_min, run_max, lb, ub)
                memory_usage = LearnersScoreCalculator.scale(learners_memory_usages[i], mem_min, mem_max, lb, ub)
                learners_emr_scores.append(LearnersScoreCalculator.__cal_emr(ub, error, runtime, memory_usage, error_weight, runtime_weight, memory_weight))

            return learners_emr_scores, learners_errors, learners_memory_usages, learners_runtime
        else:
            return None, learners_errors, learners_memory_usages, learners_runtime 
开发者ID:alipsgh,项目名称:tornado,代码行数:33,代码来源:score_calculator.py

示例14: add_result_data

# 需要导入模块: from pympler import asizeof [as 别名]
# 或者: from pympler.asizeof import asizeof [as 别名]
def add_result_data(self, title, key, data):
        if SIZE_CONTROL:
            if not self.MEM_LIMIT:
                mem_size = asizeof(self.current_task.results)
                if mem_size < 15000000:
                    self._add_result(title, key, data)
                else:
                    self.MEM_LIMIT = True
        else:
            self._add_result(title, key, data) 
开发者ID:carbonblack,项目名称:tic,代码行数:12,代码来源:__init__.py

示例15: add_results_data

# 需要导入模块: from pympler import asizeof [as 别名]
# 或者: from pympler.asizeof import asizeof [as 别名]
def add_results_data(self, results):
        if SIZE_CONTROL:
            if not self.MEM_LIMIT:
                mem_size = asizeof(self.current_task.results)
                add_size = asizeof(results)
                if (mem_size + add_size) < 15000000:
                    self._add_results(results)
                else:
                    self.MEM_LIMIT = True
        else:
            self._add_results(results) 
开发者ID:carbonblack,项目名称:tic,代码行数:13,代码来源:__init__.py


注:本文中的pympler.asizeof.asizeof方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。