• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python asizeof.asizeof函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _get_lines

    def _get_lines(self, file1, file2, lines, file1_dest, file2_dest):
        """
        Given two files to open and a sorted list of lines to get, open the files,
        retrieves the desired lines, and dumps them to specified file locations.
        """
        lines = deque(lines)
        buf1, buf2 = [], []
        line_counter, target_line = 0, lines.popleft()

        for f1_line, f2_line in zip(open(file1, 'r'), open(file2, 'r')):
            if target_line == line_counter:
                buf1.append(f1_line.strip())
                buf2.append(f2_line.strip())

                if asizeof.asizeof(buf1) + asizeof.asizeof(buf2) > \
                    self.mem_limit:
                    self._dump_bufs_to( [file1_dest, file2_dest],
                                        [buf1, buf2])

                if len(lines) != 0:
                    target_line = lines.popleft()
                else:
                    break
            line_counter += 1

        self._dump_bufs_to( [file1_dest, file2_dest],
                            [buf1, buf2])
开发者ID:urielmandujano,项目名称:Neural-Network-Machine-Translation,代码行数:27,代码来源:Parser.py


示例2: get_memory_usage

 def get_memory_usage(self):
     """
     Returns the sizes (in bytes) of the four main models that the classifier keeps in memory.
     """
     with self.lock:
         return asizeof.asizeof(self.hc), asizeof.asizeof(self.htc), asizeof.asizeof(self.tc), \
             asizeof.asizeof(self.thc)
开发者ID:alabarga,项目名称:3yp,代码行数:7,代码来源:classifier.py


示例3: test_slots_being_used

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(["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:Tinche,项目名称:attrs,代码行数:27,代码来源:test_slots.py


示例4: cleanse

    def cleanse(self, src_lang_file, tar_lang_file):
        """
        Cleans the file provided by lowercasing all words and ensuring each line in
        the text file is within min_len and max_len. Operates on two streams
        simultaneously in order to keep line to line correspondence
        """
        self._validate_file(src_lang_file), self._validate_file(tar_lang_file)
        src_dest_file = self.destdir + utilities.strip_filename_from_path(src_lang_file) + ".cleansed"
        tar_dest_file = self.destdir + utilities.strip_filename_from_path(tar_lang_file) + ".cleansed"

        if utilities.files_exist([src_dest_file, tar_dest_file]):
            return
        else:
            utilities.wipe_files([src_dest_file, tar_dest_file])
        self._print("""Cleaning data.  Ensuring uniformity of data...""")

        src_buf, tar_buf = [], []
        for src_line, tar_line in zip(open(src_lang_file), open(tar_lang_file)):
            src_line = src_line.lower().split()
            tar_line = tar_line.lower().split()

            if len(src_line) > self.min_len and len(src_line) < self.max_len and \
                len(tar_line) > self.min_len and len(tar_line) < self.max_len:
                src_buf.append(' '.join(src_line))
                tar_buf.append(' '.join(tar_line))

            if asizeof.asizeof(src_buf) + asizeof.asizeof(tar_buf) > self.mem_limit:
                self._dump_bufs_to( [src_dest_file, tar_dest_file],
                                    [src_buf, tar_buf])

        self._dump_bufs_to([src_dest_file, tar_dest_file], [src_buf, tar_buf])
        self._print("Done\n")
开发者ID:urielmandujano,项目名称:Neural-Network-Machine-Translation,代码行数:32,代码来源:Parser.py


示例5: test_copy_features_does_not_copy_entityset

def test_copy_features_does_not_copy_entityset(es):
    agg = Sum(es['log']['value'], es['sessions'])
    agg_where = Sum(es['log']['value'], es['sessions'],
                    where=IdentityFeature(es['log']['value']) == 2)
    agg_use_previous = Sum(es['log']['value'], es['sessions'],
                           use_previous='4 days')
    agg_use_previous_where = Sum(es['log']['value'], es['sessions'],
                                 where=IdentityFeature(es['log']['value']) == 2,
                                 use_previous='4 days')
    features = [agg, agg_where, agg_use_previous, agg_use_previous_where]
    in_memory_size = asizeof(locals())
    copied = [f.copy() for f in features]
    new_in_memory_size = asizeof(locals())
    assert new_in_memory_size < 2 * in_memory_size

    for f, c in zip(features, copied):
        assert f.entityset
        assert c.entityset
        assert id(f.entityset) == id(c.entityset)
        if f.where:
            assert c.where
            assert id(f.where.entityset) == id(c.where.entityset)
        for bf, bf_c in zip(f.base_features, c.base_features):
            assert id(bf.entityset) == id(bf_c.entityset)
            if bf.where:
                assert bf_c.where
                assert id(bf.where.entityset) == id(bf_c.where.entityset)
开发者ID:rgolovnya,项目名称:featuretools,代码行数:27,代码来源:test_primitive_base.py


示例6: process_response

 def process_response(self, request, response):
         req = request.META['PATH_INFO']
         if req.find('static') == -1 and req.find('media') == -1:
                 print req
                 self.end_objects = muppy.get_objects()
                 sum_start = summary.summarize(self.start_objects)
                 sum_end = summary.summarize(self.end_objects)
                 diff = summary.get_diff(sum_start, sum_end)
                 summary.print_(diff)
                 #print '~~~~~~~~~'
                 #cb = refbrowser.ConsoleBrowser(response, maxdepth=2, \
                         #str_func=output_function)
                 #cb.print_tree()
                 print '~~~~~~~~~'
                 a = asizeof(response)
                 print 'Total size of response object in kB: %s' % \
                     str(a / 1024.0)
                 print '~~~~~~~~~'
                 a = asizeof(self.end_objects)
                 print 'Total size of end_objects in MB: %s' % \
                     str(a / 1048576.0)
                 b = asizeof(self.start_objects)
                 print 'Total size of start_objects in MB: %s' % \
                     str(b / 1048576.0)
                 print '~~~~~~~~~'
         return response
开发者ID:amites,项目名称:django-general,代码行数:26,代码来源:memory_middleware.py


示例7: push

 def push(self, msg):
     serialized_msg = pickle.dumps(msg)
     from pympler.asizeof import asizeof
     print('unpickled: {}, pickled: {}'.format(
         asizeof(msg),
         asizeof(serialized_msg)
     ))
     self.output(serialized_msg)
开发者ID:hmartiro,项目名称:zircon,代码行数:8,代码来源:common.py


示例8: test_globals

    def test_globals(self):
        '''Test globals examples'''
        self._printf('%sasizeof(%s, limit=%s, code=%s) ... %s', os.linesep, 'globals()', 'MAX', False, '-glob[als]')
        asizeof.asizeof(globals(), limit=self.MAX, code=False, stats=1)
        self._print_functions(globals(), 'globals()', opt='-glob[als]')

        self._printf('%sasizesof(%s, limit=%s, code=%s) ... %s', os.linesep, 'globals(), locals()', 'MAX', False, '-glob[als]')
        asizeof.asizesof(globals(), locals(), limit=self.MAX, code=False, stats=1)
        asizeof.asized(globals(), align=0, detail=self.MAX, limit=self.MAX, code=False, stats=1)
开发者ID:diffway,项目名称:pympler,代码行数:9,代码来源:test_asizeof.py


示例9: test_methods

    def test_methods(self):
        '''Test sizing methods and functions
        '''
        def foo():
            pass

        s1 = asizeof.asizeof(self.test_methods, code=True)
        s2 = asizeof.asizeof(TypesTest.test_methods, code=True)
        s3 = asizeof.asizeof(foo, code=True)
开发者ID:diffway,项目名称:pympler,代码行数:9,代码来源:test_asizeof.py


示例10: test_adict

 def test_adict(self):
     '''Test asizeof.adict()
     '''
     pdict = PseudoDict()
     size1 = asizeof.asizeof(pdict)
     asizeof.adict(PseudoDict)
     size2 = asizeof.asizeof(pdict)
     # TODO: come up with useful assertions
     self.assertEqual(size1, size2)
开发者ID:diffway,项目名称:pympler,代码行数:9,代码来源:test_asizeof.py


示例11: run

def run(dicp="~/dev/kaggle/fb5/pdic.map", datap="~/dev/kaggle/fb5/train.tab", lr=1., numbats=100, epochs=10):
    dic, revdic = loaddict(expanduser(dicp))
    print len(dic)
    traindata, golddata = loaddata(expanduser(datap), top=10000)
    print asizeof(traindata), golddata.dtype
    m = SpatialEmb(dim=len(dic))

    m.train([traindata], golddata).adagrad(lr=lr).cross_entropy()\
        .split_validate(splits=100, random=True).cross_entropy().accuracy()\
        .train(numbats, epochs)
开发者ID:lukovnikov,项目名称:teafacto,代码行数:10,代码来源:fb5.py


示例12: test_asizer

 def test_asizer(self):
     '''Test Asizer properties.
     '''
     sizer = asizeof.Asizer()
     obj = 'unladen swallow'
     mutable = [obj]
     sizer.asizeof(obj)
     self.assertEqual(sizer.total, asizeof.asizeof(obj))
     sizer.asizeof(mutable, mutable)
     self.assertEqual(sizer.duplicate, 1)
     self.assertEqual(sizer.total, asizeof.asizeof(obj, mutable))
开发者ID:diffway,项目名称:pympler,代码行数:11,代码来源:test_asizeof.py


示例13: add_results_data

 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:TheDr1ver,项目名称:crits_services,代码行数:11,代码来源:__init__.py


示例14: getSizeOfMgrs

 def getSizeOfMgrs(self):
     """ get size of object """
     appGlobal = config['pylons.app_globals']
     
     result = {}
     result['threadmgr'] = asizeof(appGlobal.threadMgr)
     result['packagemgr'] = asizeof(appGlobal.packageMgr)
     result['montior'] = asizeof(appGlobal.agentMonitor)
     result['all'] = asizeof(appGlobal)
     
     return doneResult(request, response, result = result, controller = self)
开发者ID:cronuspaas,项目名称:cronusagent,代码行数:11,代码来源:agentaction.py


示例15: test_private_slots

    def test_private_slots(self):
        class PrivateSlot(object):
            __slots__ = ('__data',)
            def __init__(self, data):
                self.__data = data

        data = [42] * 100
        container = PrivateSlot(data)
        size1 = asizeof.asizeof(container)
        size2 = asizeof.asizeof(data)
        self.assertTrue(size1 > size2, (size1, size2))
开发者ID:pympler,项目名称:pympler,代码行数:11,代码来源:test_asizeof.py


示例16: test_asizeof

    def test_asizeof(self):
        '''Test asizeof.asizeof()
        '''
        self.assertEqual(asizeof.asizeof(), 0)

        objs = [Foo(42), ThinFoo("spam"), OldFoo(67)]
        total = asizeof.asizeof(*objs)
        sizes = list(asizeof.asizesof(*objs))
        sum = 0
        for sz in sizes:
            sum += sz
        self.assertEqual(total, sum, (total, sum))
开发者ID:diffway,项目名称:pympler,代码行数:12,代码来源:test_asizeof.py


示例17: dumpMonitorValues

 def dumpMonitorValues(self):
     ''' dump all monitor values as json string '''
     result = {}
     for (service, mname) in self.__monitorValues:
         key = '%s.%s' % (service, mname)
         result[key] = self.__monitorValues[(service, mname)]
     result['values'] = asizeof(self.__monitorValues)
     result['tasks'] = asizeof(self.__monitorTasks)
     result['messages'] = asizeof(self.__monitorMessages)
     result['tags'] = asizeof(self.__monitorTags)
     result['messagekeys'] = '%s' % self.__monitorMessages
     return result
开发者ID:anzarafaq,项目名称:cronusagent,代码行数:12,代码来源:monitor.py


示例18: test_closure

    def test_closure(self):
        '''Test sizing closures.
        '''
        def outer(x):
            def inner():
                return x
            return inner

        data = [1] * 1000
        closure = outer(data)
        size_closure = asizeof.asizeof(closure, code=True)
        size_data = asizeof.asizeof(data)
        self.assertTrue(size_closure >= size_data, (size_closure, size_data))
开发者ID:diffway,项目名称:pympler,代码行数:13,代码来源:test_asizeof.py


示例19: split_train_tune_test

    def split_train_tune_test(self, src_file, src_piv_file, piv_tar_file, tar_file,
        train_split, test_split):
        """
        Splits the full datafiles into test, tune, and train sets.
        Receives 4 files as parameters and 2 decimals indicating the percentage of
        data to be used as train, tune, and test data. If line 1 in src langs is
        in test, then line 1 in tar langs will also be in test. Etc.
        """
        utilities.make_dir(self.traindir)
        utilities.make_dir(self.tunedir)
        utilities.make_dir(self.testdir)

        self._validate_file(src_file), self._validate_file(src_piv_file)
        self._validate_file(piv_tar_file), self._validate_file(tar_file)
        assert train_split + test_split <= 1 , "Invalid size for train, tune, and test splits"

        train_files, tune_files, test_files = self._ttt_filenames(src_file, src_piv_file, piv_tar_file, tar_file)
        if utilities.ttt_files_exist(train_files, tune_files, test_files):
            return
        else:
            utilities.ttt_wipe_files(train_files, tune_files, test_files)

        self._print("""Splitting data into train, tune, and test sets...""")
        train, tune, test = [[] ,[], [], []],  [[], [], [], []], [[], [], [], []]
        for src_line, src_piv_line, piv_tar_line, tar_line in \
            zip_longest(open(src_file), open(src_piv_file), open(piv_tar_file), open(tar_file)):

            x = numpy.random.sample()
            if x < train_split:
                self._add_line_to(train[0], src_line)
                self._add_line_to(train[1], src_piv_line)
                self._add_line_to(train[2], piv_tar_line)
                self._add_line_to(train[3], tar_line)
            elif x >= train_split and x < train_split + test_split:
                self._add_line_to(tune[0], src_line)
                self._add_line_to(tune[1], src_piv_line)
                self._add_line_to(tune[2], piv_tar_line)
                self._add_line_to(tune[3], tar_line)
            else:
                self._add_line_to(test[0], src_line)
                self._add_line_to(test[1], src_piv_line)
                self._add_line_to(test[2], piv_tar_line)
                self._add_line_to(test[3], tar_line)

            if asizeof.asizeof(train) + asizeof.asizeof(tune) + \
                asizeof.asizeof(test) > self.mem_limit:
                self._dump_ttt_bufs_to(train, tune, test, train_files, tune_files, test_files)

        self._dump_ttt_bufs_to(train, tune, test, train_files, tune_files, test_files)
        self._print("Done\n")
开发者ID:urielmandujano,项目名称:Neural-Network-Machine-Translation,代码行数:50,代码来源:Parser.py


示例20: test_weakref

 def test_weakref(self):
     '''Test sizing weak references.
     '''
     alive = Foo('alive')
     aref = weakref.ref(alive)
     dead = Foo('dead')
     dref = weakref.ref(dead)
     del dead
     aref_size = asizeof.asizeof(aref)
     self.assertTrue(aref_size > asizeof.asizeof(alive), aref_size)
     refs = asizeof.named_refs(aref)
     # TODO: Should a weakref return ('ref', obj)?
     dref_size = asizeof.asizeof(dref)
     self.assertTrue(dref_size > 0, dref_size)
     self.assertNotEqual(dref_size, aref_size)
     refs = asizeof.named_refs(dref)
开发者ID:diffway,项目名称:pympler,代码行数:16,代码来源:test_asizeof.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python muppy.get_objects函数代码示例发布时间:2022-05-27
下一篇:
Python pymouse.PyMouse类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap