perf_util.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:indy-plenum 作者: hyperledger 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号