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


Python sys.getsizeof函数代码示例

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


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


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