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

Python sys.getsizeof函数代码示例

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

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



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

示例1: precompute_GLCM_PCA_Cache

def precompute_GLCM_PCA_Cache(images_dir_path, images_names):
    print '--------------------------------------------------------------------------'
    start = time.time()
    flattened_descriptors = [None] * len(images_names);
    for i in xrange(len(images_names)):
        image_name = images_names[i]
        raw_descriptor = getGLCM(images_dir_path, image_name)
        flattened_descriptors[i] = raw_descriptor.flatten()

    PCA_train_set = numpy.array(flattened_descriptors)

    pca = PCA(n_components=0.8)
    print 'RAW:'
    print PCA_train_set.shape
    print PCA_train_set
    print ''
    transformedTrainSet = pca.fit_transform(PCA_train_set)
    print 'PCAed:'
    print transformedTrainSet.shape
    print transformedTrainSet
    print ''

    end = time.time()
    secs = end - start
    msecs = secs * 1000  # millisecs

    for i in xrange(len(images_names)):
        image_name = images_names[i]
        glcm_PCA_cache[image_name] = transformedTrainSet[i]

    print 'PCA GLCMs cache size:' + repr(sys.getsizeof(glcm_PCA_cache)) + ' bytes'
    print 'PCA GLCMs cache dim:' + repr(len(glcm_PCA_cache.keys())) + '*' + repr(len(glcm_PCA_cache[glcm_PCA_cache.keys()[0]]))
    print 'PCA GLCMs descriptors size:' + repr(sys.getsizeof(glcm_PCA_cache.values())) + ' bytes'
    print 'PCA GLCM elapsed time: %f s (%f ms)' % (secs, msecs)
    print '--------------------------------------------------------------------------'
开发者ID:ala--rs88,项目名称:disser,代码行数:35,代码来源:brodatz_database_descriptors.py


示例2: regulardict_to_ordereddict

def regulardict_to_ordereddict():
    """sort a dict by it's key, value, or customized rules. user can choose ascend or descend.
    OrderedDict其实并不是生成一个全新的字典。OrderedDict只是生成了一个新的Key的序列, 然后通过维护这个
    Key序列来决定输出的顺序。
    
    如果 d 的 key 和 value 都是可排序的数字或者字符串, 而我们不引用任何复杂的规则, 仅仅是根据key或者
    value来排序, 那么生成的OrderedDict的内存开销就不变, 因为仅仅是在调用iter方法时, 临时排序输出即可。
    而如果使用形如:
        根据value中第二个元素进行排序
    那么就会带来额外的内存开销。本例中就是这种情况。
    """
    d = {"c":[1, 3],
         "a":[3, 2],
         "b":[2, 1]}
    
    print("{:=^100}".format("sort by value, ascend"))
    od1 = OrderedDict( sorted(list(d.items()), 
                             key=lambda t: t[1], # t[0]指根据key排序, t[1]指根据value排序
                             reverse = False) ) # True指逆序排序,False指正序排序
    for k,v in list(od1.items()):
        print(k,v) ## 看看是否按照设定有序输出
        
    print("{:=^100}".format("sort by value[1], descend"))
    od2 = OrderedDict( sorted(list(d.items()), 
                             key=lambda t: t[1][1], # t[1][1]指根据value[1]排序
                             reverse = True) )
    for k,v in list(od2.items()):
        print(k,v) ## 看看是否按照设定有序输出
        
    print("原始字典占用内存大小为: %s" % sys.getsizeof(d)) # 288
    print("有序字典占用内存大小为: %s" % sys.getsizeof(od1)) # 1304
    print("有序字典占用内存大小为: %s" % sys.getsizeof(od2)) # 1304
    print("d == od1? %s" % (d == od1)) # True
    print("d == od2? %s" % (d == od2)) # True
开发者ID:MacHu-GWU,项目名称:six-demon-bag,代码行数:34,代码来源:_note_ordereddict.py


示例3: init_cache

  def init_cache(filename, cache_type, classes):
    assert cache_type in ('FULL', 'ENCODED', 'NONE')
    print('Load images in the cache: {}'.format(cache_type))
    generator, size = ObjectDetectorJson.json_iterator(filename, classes)
    items = [pickle.loads(item) for item in generator()]

    def _read_image_from_disk(im_path, cache_type):
      if cache_type == 'ENCODED':
        with open(im_path, 'rb') as file:
          encoded_image = file.read()
          encoded_image = np.array(bytearray(encoded_image), dtype=np.uint8)
        return encoded_image
      if cache_type == 'FULL':
        image = imread(im_path)
        return image

    items = tqdm(items, total=size, unit='images')
    total_cache_usage = 0
    for item in items:
      im_path = item['image']
      if cache_type != 'NONE':
        image = _read_image_from_disk(im_path, cache_type)
      else:
        image = None

      annotation = ObjectDetectorJson._get_annotation(item, classes)
      ObjectDetectorJson._cache[im_path] = [image, annotation]

      if isinstance(image, np.ndarray):
        total_cache_usage += image.nbytes
      else:
        total_cache_usage += sys.getsizeof(image)
      total_cache_usage += sys.getsizeof(annotation)  # Bad estimation

      items.set_postfix({'cache usage (GB)': total_cache_usage / 1024 ** 3})
开发者ID:undeadinu,项目名称:training_toolbox_tensorflow,代码行数:35,代码来源:object_detector_json.py


示例4: start

    def start(self, paras=None, refresh=True):
        """

        :param paras:
        :param refresh: True表示刷新绩效且需要释放资源,即用户一个完整的请求已经结束;False的情况主要是参数优化时批量运行回测。
        """
        try:
            if not self.__initialized:
                self.init()
            gc.collect()
            self.__is_alive = True
            if paras is not None:
                self.__strategy.set_parameters(paras)
            self.__strategy_engine.start()
            self.__data_generator.start()
            if refresh:
                self.__performance_manager = self.__strategy_engine.wait(self.__get_performance_manager)
                self.__data_generator.stop()
                if MEMORY_DEBUG:
                    print('gb:\n%s' % sys.getsizeof(gc.garbage))  # 写日志,计算垃圾占用的内存等
                    gb_log = {}
                    for gb in gc.garbage:
                        type_ = type(gb)
                        if type_ not in gb_log:
                            gb_log[type_] = 0
                        gb_log[type_] += sys.getsizeof(gb)
                    print(gb_log)
                result = self.__performance_manager
            else:
                result = self.__strategy_engine.wait()
            self.log(self.__timer.time("策略运算完成,耗时:{0}"), logging.INFO)
            return result
        except Exception as e:
            self.stop()
            raise e
开发者ID:testmana2,项目名称:Bigfish,代码行数:35,代码来源:run_time_singal.py


示例5: GetSizeOfCache

def GetSizeOfCache():
    """ Returns number of bytes held in cache.
        returns:
            int - size of cache including static and dynamic
    """
    global _static_data, _dynamic_data
    return sys.getsizeof(_static_data) + sys.getsizeof(_dynamic_data)
开发者ID:Apple-FOSS-Mirror,项目名称:xnu,代码行数:7,代码来源:caching.py


示例6: frame_profile

def frame_profile(frame_idx, serial_data_path, pickle_path,
                  mol_types, coords, sys_type, assoc_sel_idxs, assoc_type, inx_type):

                
    inxs, system, assoc = profile_coords(mol_types, coords, sys_type, assoc_sel_idxs, assoc_type, inx_type)

    # data output
    inx_type.pdb_serial_output(inxs[inx_type], serial_data_path, delim=" ")

    # persistent storage
    with open(pickle_path, 'wb') as f:
        pickle.dump(inxs, f)

    print("--------------------------------------------------------------------------------")
    print("frame", frame_idx)
    print("----------------------------------------")
    print("size of inxs {}".format(sys.getsizeof(inxs)))
    print("size of system {}".format(sys.getsizeof(system)))
    print("size of assoc {}".format(sys.getsizeof(assoc)))
    if len(inxs[inx_type]) > 0:
        print(len(inxs[inx_type]), "intermolecular hydrogen bonds")
        for inx in inxs[inx_type]:
            inx.pp()
    else:
        print(0, "intermolecular hydrogen bonds")
开发者ID:salotz,项目名称:mast,代码行数:25,代码来源:example_script.py


示例7: obtenerCodigoHTMLparaCedula

def obtenerCodigoHTMLparaCedula(cedula):
    
    # direccion web de consulta por numero de cedula del tse
    URL = 'http://www.consulta.tse.go.cr/consulta_persona/consulta_cedula.aspx'
    # Crear instancia del navegador
    b = mechanize.Browser()
    # Cargar la pagina
    r = b.open(URL)
    # Obtener el codigo HTML
    htmlSource = r.read()
    print 'recibido HTML de ' + str(sys.getsizeof(htmlSource)) + ' bytes.'
    # Buscar Captcha dentro del codigo HTML
    valorCaptcha = re.search(r'[A-Z0-9]{6}\.bmp', htmlSource).group().rstrip('.bmp')
    # Seleccionamos el formulario
    b.select_form('form1')
    # Llenamos los campos requeridos para la consulta
    b['txtcedula'] = cedula
    b['txtcodigo'] = valorCaptcha
    # Enviamos el formulario y esperamos la respuesta
    print 'enviando formulario con cedula [' + cedula + '] y captcha [' + valorCaptcha + ']'
    respuesta = b.submit()
    # Obtenermos el codigo HTML de la respuesta
    htmlSource = respuesta.read()
    print 'respuesta recibida de ' + str(sys.getsizeof(htmlSource)) + ' bytes.'
    return htmlSource
开发者ID:nehemiascr,项目名称:python-git,代码行数:25,代码来源:tseParser.py


示例8: testSizeOf

    def testSizeOf(self):
        try:
            if hasattr(sys, 'getsizeof'):
                sys.getsizeof(univ.noValue)

        except PyAsn1Error:
            assert False, 'sizeof failed for NoValue object'
开发者ID:luke-chang,项目名称:gecko-1,代码行数:7,代码来源:test_univ.py


示例9: dummy_send

 def dummy_send(self, data, noftimes=1):
   self.sendstart_time = time.time()
   nofBs_sent = 0
   logging.info('dummy_send started at time=%s', time.time() )
   logging.info('noftimes=%s', noftimes)
   for i in range(0, int(noftimes)):
     if self.proto == 'tcp':
       try:
         self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         self.sock.connect(self.dst_addr)
         self.sock.sendall(data)
         datasize = sys.getsizeof(data)-37 #37 is python string format header length
         logging.info('tcp_sent datasize=%sB', datasize)
         nofBs_sent += datasize
       except socket.error, e:
         if isinstance(e.args, tuple):
           logging.error('errno is %d', e[0])
           if e[0] == errno.EPIPE:
             logging.error('Detected remote peer disconnected')
           else:
             # determine and handle different error
             pass
         else:
           logging.error('socket error')
     elif self.proto == 'udp':
       self.sock.sendto(data, self.dst_addr)
       datasize = sys.getsizeof(data)-37 #37 is python string format header length
       nofBs_sent += datasize
       logging.info('udp_sent datasize=%sB', sys.getsizeof(data))
开发者ID:mfatihaktas,项目名称:sim_rel-,代码行数:29,代码来源:sender.py


示例10: get_policies

    def get_policies(self):
        self.controllerUrl = 'http://'+self.controllerIp+':8080/controller/nb/v2/statistics/default/flow'

        resp, content = self.h.request(self.controllerUrl, "GET")
        print sys.getsizeof(content)

        allFlowStats = json.loads(content)
        flowStats = allFlowStats['flowStatistics']

        for fs in flowStats:
            print "\nSwitch ID : " + fs['node']['id']
            print '{0:8} {1:8} {2:5} {3:15}'.format('Count', 'Action', 'Port', 'DestIP')
            for aFlow in fs['flowStatistic']:
                count = aFlow['packetCount']
                actions = aFlow['flow']['actions']
                actionType = ''
                actionPort = ''
                #print actions
                if(type(actions) == type(list())):
                    actionType = actions[0]['type']
                    if actions[0].get('port') is not None:
                        actionPort = actions[0]['port']['id']
                else:
                    actionType = actions['type']
                    actionPort = actions['port']['id']
                dst = aFlow['flow']['match']['matchField'][0]['value']
                print '{0:8} {1:8} {2:5} {3:15}'.format(count, actionType, actionPort, dst)
开发者ID:posco,项目名称:policy-aware-plan,代码行数:27,代码来源:policy_lookup.py


示例11: main

def main():
    
    # 기본 floating point 활용
    i = 0.1
    boolean_status = True
    
    while boolean_status:
        print i
        i += 0.1
        if i == 2:
            boolean_status = False
    
    # 오류를 보정한 decimal 자료형 활용
    boolean_status = True
    
    import decimal 
    import sys
    dcimal_i = decimal.Decimal('0.1')
    dcimal_j = decimal.Decimal('0.1')
    
    while boolean_status:
        print dcimal_i
        dcimal_i += dcimal_j
        if dcimal_i == 2:
            boolean_status = False
    
    print '=='*6
    print 'i'
    print type(i)
    print sys.getsizeof(i)
    print '=='*6
    print 'dcimal_i'
    print type(dcimal_i)
    print sys.getsizeof(dcimal_i) # 일반적인 float형에 비해 3배의 공간을 필요
开发者ID:nowol79,项目名称:Python_Lectures,代码行数:34,代码来源:floating_point_number_error.py


示例12: sendMessage

def sendMessage(csock, message):
	print('Transmitting', sys.getsizeof(message), "bytes")
	csock.send(bytes(str(sys.getsizeof(message)), "utf-8"))
	csock.recv(4)
	csock.send(bytes(message, "utf-8"))
	csock.recv(4)
	print('Transmission complete.')
开发者ID:jackhamilton,项目名称:CRYPTO-Server,代码行数:7,代码来源:net.py


示例13: evaluate_node

    def evaluate_node(self, node):
        self.bytes_received += sys.getsizeof(node.parameters)
        self.bytes_received += sys.getsizeof(node.node_id)

        self.role_satisfaction_map[node.node_id] = \
            set([role_id for (role_id, role_criteria) in \
                enumerate(self.role_criterias) if role_criteria.evaluate_against(node.parameters) > 0])
开发者ID:triskadecaepyon,项目名称:DF_RoleMatrix,代码行数:7,代码来源:naive_centralized_algorithm.py


示例14: __sizeof__

 def __sizeof__(self):
     size = sys.getsizeof(self.sigma) + \
            sys.getsizeof(self.unit_num) + \
            sys.getsizeof(list(self.w)) + \
            sys.getsizeof(list(self.X)) + \
            sys.getsizeof(list(self.T))
     return size
开发者ID:zachary-zzc,项目名称:handwriting,代码行数:7,代码来源:bpnetwork.py


示例15: to_externalizable

 def to_externalizable(self):
     compressed = zlib.compress(pickle.dumps(self.docs))
     logger.info(
         "Compression changed size of metric store from [%d] bytes to [%d] bytes"
         % (sys.getsizeof(self.docs), sys.getsizeof(compressed))
     )
     return compressed
开发者ID:elastic,项目名称:rally,代码行数:7,代码来源:metrics.py


示例16: main

def main(data_txt_path, label_txt_path, stride=25,
         images_folder='roadC621/'):
    """
    Train a neural network with patches of patch_size x patch_size
    (as given via the module network_path).

    Parameters
    ----------
    network_path : str
        Path to a Python script with a function generate_nnet(feats) which
        returns a neural network
    image_batch_size : int
    stride : int
    """
    assert image_batch_size >= 1
    assert stride >= 1
    features, labels = load_data_raw_images(train_images_folder=images_folder)
    mem_size = (sys.getsizeof(42) * len(features) * features[0].size +
                sys.getsizeof(42) * len(labels) * labels[0].size)
    logging.info("Loaded %i data images with their labels (approx %s)",
                 len(features),
                 utils.sizeof_fmt(mem_size))
    nn_params = {'training': {'image_batch_size': image_batch_size,
                              'stride': stride}}

    logging.info("## Network: %s", network_path)
    network = imp.load_source('sst.network', network_path)
    logging.info("Fully network: %s", str(network.fully))
    nn_params['code'] = inspect.getsource(network)
    nn_params['fully'] = network.fully
    nn_params['patch_size'] = network.patch_size
    assert nn_params['patch_size'] > 0

    labeled_patches = get_patches(features[:1],
                                  labels[:1],
                                  nn_params=nn_params)

    feats, _ = get_features(labeled_patches, fully=nn_params['fully'])
    net1 = network.generate_nnet(feats)
    for block in range(0, len(features), image_batch_size):
        from_img = block
        to_img = block + image_batch_size
        logging.info("Training on batch %i - %i of %i total",
                     from_img,
                     to_img,
                     len(features))
        labeled_patches = get_patches(features[from_img:to_img],
                                      labels[from_img:to_img],
                                      nn_params=nn_params,
                                      stride=stride)
        logging.info(("labeled_patches[0].shape: %s , "
                      "labeled_patches[1].shape: %s"),
                     labeled_patches[0].shape,
                     labeled_patches[1].shape)
        net1 = train_nnet(labeled_patches, net1, fully=nn_params['fully'])

    model_pickle_name = 'nnet1-trained.pickle'
    utils.serialize_model(net1,
                          filename=model_pickle_name,
                          parameters=nn_params)
开发者ID:MarvinTeichmann,项目名称:Street-Segmentation-Toolkit,代码行数:60,代码来源:create_database.py


示例17: read_stbl

def read_stbl(bstr):
    """Parse a string table (ID 0x220557DA)"""

    f = utils.BReader(bstr)
    if f.get_raw_bytes(4) != b'STBL':
        raise utils.FormatException("Bad magic")
    version = f.get_uint16()
    if version != 5:
        raise utils.FormatException("We only support STBLv5")
    compressed = f.get_uint8()
    numEntries = f.get_uint64()
    f.off += 2
    mnStringLength = f.get_uint32() # This is the total size of all
                                    # the strings plus one null byte
                                    # per string (to make the parsing
                                    # code faster, probably)

    entries = {}
    size = 0
    for _ in range(numEntries):
        keyHash = f.get_uint32()
        flags = f.get_uint8() # What is in this?
        length = f.get_uint16()
        val = f.get_raw_bytes(length).decode('utf-8')
        entries[keyHash] = val
        size += sys.getsizeof(keyHash, val)
    size += sys.getsizeof(entries)
    return entries
开发者ID:abiggerhammer,项目名称:s4py,代码行数:28,代码来源:stbl.py


示例18: walkdir

def walkdir(pathname):
    total_files = files_number(pathname)
    currentsize = 0
    memsizeapprox = 0
    numfiles = 0
    sizeofint = sys.getsizeof(int())
    for root, dirs, files in os.walk(pathname):
        for name in files:
            fullname = os.path.join(root, name)
            numfiles += 1
            try:
                if not os.path.isfile(fullname):
                    sz = 0
                else:
                    sz = os.path.getsize(fullname)
                # i should use sys.getsizeof here
                memsizeapprox += sys.getsizeof(fullname) + sizeofint
                currentsize += sz
                print_update(
                    "%d/%d, %s (Memsize: %s)" % (numfiles, total_files, human(currentsize), human(memsizeapprox))
                )
                yield fullname, sz
            except OSError:
                print("""Cannot read '%s'""" % fullname, file=sys.stderr)
                pass
开发者ID:jbd,项目名称:packo,代码行数:25,代码来源:packo.py


示例19: sendLine

 def sendLine(self, line, queue=True):
     ''' normal sendLine with flood protection '''
     if type(line) == unicode:
         try:
             line = line.encode('utf-8')
         except UnicodeDecodeError:
             pass
     if line.startswith(('PRIVMSG', 'NOTICE')):
         length = sys.getsizeof(line) - sys.getsizeof(type(line)()) + 2
         if length <= self.floodBuffer - self._floodCurrentBuffer:
             # buffer isn't full, send
             self.updateFloodBuffer(length)
             irc.IRCClient.sendLine(self, line)
             return True
         else:
             # send an invalid command
             if queue:
                 with self._floodLock:
                     self._floodQueue.append(line)
             if not self._floodWaitInvalid:
                 irc.IRCClient.sendLine(self, '_!')
                 self._floodWaitInvalid = True
             return False
     else:
         irc.IRCClient.sendLine(self, line)
         return True
开发者ID:ohad258,项目名称:nautilus,代码行数:26,代码来源:bot.py


示例20: find_the_most_like

def find_the_most_like(resp, first_fifty=50):
    """top 50 most liked"""
    most_liked = sorted(resp.iteritems(), key=lambda x: -x[1])[:first_fifty]
    print sys.getsizeof(most_liked)
    # not sure how much optimation is being done using sorted vs sort
    ## but it is using 472 bytes using sorted.
    return most_liked
开发者ID:slopeofhope81,项目名称:get_best_combo,代码行数:7,代码来源:main.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python sys.getswitchinterval函数代码示例发布时间:2022-05-27
下一篇:
Python sys.getrefcount函数代码示例发布时间: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