def test_itemsize(self): '''Test asizeof.itemsize() ''' objects = [1, True, None, ()] for o in objects: self.assertEqual(asizeof.itemsize(o), type(o).__itemsize__) itemsizes = [({}, asizeof._sizeof_CPyDictEntry), (set(), asizeof._sizeof_Csetentry), ] for o, itemsize in itemsizes: self.assertEqual(asizeof.itemsize(o), itemsize)
def _print_functions(self, obj, name=None, align=8, detail=MAX, code=False, limit=MAX, opt='', **unused): if name: self._printf('%sasizeof functions for %s ... %s', os.linesep, name, opt) self._printf('%s(): %s', ' basicsize', asizeof.basicsize(obj)) self._printf('%s(): %s', ' itemsize', asizeof.itemsize(obj)) self._printf('%s(): %r', ' leng', asizeof.leng(obj)) self._printf('%s(): %s', ' refs', _repr(asizeof.refs(obj))) self._printf('%s(): %s', ' flatsize', asizeof.flatsize(obj, align=align)) # , code=code self._printf( '%s(): %s', ' asized', asizeof.asized(obj, align=align, detail=detail, code=code, limit=limit))
def test_flatsize(self): '''Test asizeof.flatsize() ''' l = ["spam", 2, 3, 4, "eggs", 6, 7, 8] for _type in (list, tuple, set, frozenset): data = _type(l) bsz = asizeof.basicsize(data) isz = asizeof.itemsize(data) lng = asizeof.leng(data) fsz = asizeof.flatsize(data) self.assertEqual(fsz, bsz + (lng * isz), (fsz, bsz, lng, isz)) self.assertRaises(ValueError, asizeof.flatsize, l, **{'align': 3})
def test_long(self): '''Test int and long examples''' try: _L5d = long(1) << 64 _L17d = long(1) << 256 t = '<int>/<long>' except NameError: _L5d = 1 << 64 _L17d = 1 << 256 t = '<int>' self._printf('%sasizeof(%s, align=%s, limit=%s) ... %s', os.linesep, t, 0, 0, '-int') for o in (1024, 1000000000, 1.0, 1.0e100, 1024, 1000000000, self.MAX, 1 << 32, _L5d, -_L5d, _L17d, -_L17d): self._printf(" asizeof(%s) is %s (%s + %s * %s)", _repr(o), asizeof.asizeof(o, align=0, limit=0), asizeof.basicsize(o), asizeof.leng(o), asizeof.itemsize(o))
quit(2) print("------------------------------------------------------------") print("Controller capabilities : {}".format(network.controller.capabilities)) print("Controller node capabilities : {}".format( network.controller.node.capabilities)) print("------------------------------------------------------------") print("Driver statistics : {}".format(network.controller.stats)) print("------------------------------------------------------------") print("Nodes in network : {}".format(network.nodes_count)) print("------------------------------------------------------------") print("Memory use : ") print("------------------------------------------------------------") print("Memory use for network {} : ".format(network.home_id_str)) print(" asizeof : {} bytes".format(asizeof(network))) print(" basicsize : {} bytes".format(basicsize(network))) print(" itemsize : {} bytes".format(itemsize(network))) print(" flatsize : {} bytes".format(flatsize(network))) print("------------------------------------------------------------") manager = network.manager print("Memory use for manager : ") print(" asizeof : {} bytes".format(asizeof(manager))) print(" basicsize : {} bytes".format(basicsize(manager))) print(" itemsize : {} bytes".format(itemsize(manager))) print(" flatsize : {} bytes".format(flatsize(manager))) print("------------------------------------------------------------") print("Memory use for controller : ") print(" asizeof : {} bytes".format(asizeof(network.controller))) print(" basicsize : {} bytes".format(basicsize(network.controller))) print(" itemsize : {} bytes".format(itemsize(network.controller))) print(" flatsize : {} bytes".format(flatsize(network.controller))) print("------------------------------------------------------------")
print "Can't start network! Look at the logs in OZW_Log.log" quit(2) print "------------------------------------------------------------" print "Controller capabilities : %s" % network.controller.capabilities print "Controller node capabilities : %s" % network.controller.node.capabilities print "------------------------------------------------------------" print "Driver statistics : %s" % network.controller.stats print "------------------------------------------------------------" print "Nodes in network : %s" % network.nodes_count print "------------------------------------------------------------" print "Memory use : " print "------------------------------------------------------------" print "Memory use for network %s : " % (network.home_id_str) print " asizeof : %s bytes" % (asizeof(network)) print " basicsize : %s bytes" % (basicsize(network)) print " itemsize : %s bytes" % (itemsize(network)) print " flatsize : %s bytes" % (flatsize(network)) print "------------------------------------------------------------" manager = network.manager print "Memory use for manager : " print " asizeof : %s bytes" % (asizeof(manager)) print " basicsize : %s bytes" % (basicsize(manager)) print " itemsize : %s bytes" % (itemsize(manager)) print " flatsize : %s bytes" % (flatsize(manager)) print "------------------------------------------------------------" print "Memory use for controller : " print " asizeof : %s bytes" % (asizeof(network.controller)) print " basicsize : %s bytes" % (basicsize(network.controller)) print " itemsize : %s bytes" % (itemsize(network.controller)) print " flatsize : %s bytes" % (flatsize(network.controller)) print "------------------------------------------------------------"