當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。