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

Python support.calcobjsize函数代码示例

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

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



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

示例1: test_sizeof

 def test_sizeof(self):
     basesize = support.calcobjsize('P2nN2Pn')
     check = self.check_sizeof
     self.assertEqual(object.__sizeof__(io.BytesIO()), basesize)
     check(io.BytesIO(), basesize )
     check(io.BytesIO(b'a'), basesize + 1 + 1 )
     check(io.BytesIO(b'a' * 1000), basesize + 1000 + 1 )
开发者ID:SantoKo,项目名称:RPI3-Desktop,代码行数:7,代码来源:test_memoryio.py


示例2: test_sizeof

    def test_sizeof(self):
        def XXXROUNDUP(n):
            if n <= 1:
                return n
            if n <= 128:
                return (n + 3) & ~3
            return 1 << (n - 1).bit_length()

        basesize = support.calcobjsize('Pii')
        nodesize = struct.calcsize('hP3iP0h')
        def sizeofchildren(node):
            if node is None:
                return 0
            res = 0
            hasstr = len(node) > 1 and isinstance(node[-1], str)
            if hasstr:
                res += len(node[-1]) + 1
            children = node[1:-1] if hasstr else node[1:]
            if children:
                res += XXXROUNDUP(len(children)) * nodesize
                for child in children:
                    res += sizeofchildren(child)
            return res

        def check_st_sizeof(st):
            self.check_sizeof(st, basesize + nodesize +
                                  sizeofchildren(st.totuple()))

        check_st_sizeof(parser.expr('2 + 3'))
        check_st_sizeof(parser.expr('2 + 3 + 4'))
        check_st_sizeof(parser.suite('x = 2 + 3'))
        check_st_sizeof(parser.suite(''))
        check_st_sizeof(parser.suite('# -*- coding: utf-8 -*-'))
        check_st_sizeof(parser.expr('[' + '2,' * 1000 + ']'))
开发者ID:M31MOTH,项目名称:cpython,代码行数:34,代码来源:test_parser.py


示例3: test_sizeof

 def test_sizeof(self):
     basesize = support.calcobjsize('P2n2Pn')
     check = self.check_sizeof
     self.assertEqual(object.__sizeof__(io.BytesIO()), basesize)
     check(io.BytesIO(), basesize )
     n = 1000  # use a variable to prevent constant folding
     check(io.BytesIO(b'a' * n), basesize + sys.getsizeof(b'a' * n))
开发者ID:1st1,项目名称:cpython,代码行数:7,代码来源:test_memoryio.py


示例4: test_sizeof

 def test_sizeof(self):
     BLOCKLEN = 62
     basesize = support.calcobjsize('2P4nlP')
     blocksize = struct.calcsize('2P%dP' % BLOCKLEN)
     self.assertEqual(object.__sizeof__(deque()), basesize)
     check = self.check_sizeof
     check(deque(), basesize + blocksize)
     check(deque('a'), basesize + blocksize)
     check(deque('a' * (BLOCKLEN - 1)), basesize + blocksize)
     check(deque('a' * BLOCKLEN), basesize + 2 * blocksize)
     check(deque('a' * (42 * BLOCKLEN)), basesize + 43 * blocksize)
开发者ID:5outh,项目名称:Databases-Fall2014,代码行数:11,代码来源:test_deque.py


示例5: test_sizeof

 def test_sizeof(self):
     BLOCKLEN = 62
     basesize = support.calcobjsize("2P4nlP")
     blocksize = struct.calcsize("2P%dP" % BLOCKLEN)
     self.assertEqual(object.__sizeof__(deque()), basesize)
     check = self.check_sizeof
     check(deque(), basesize + blocksize)
     check(deque("a"), basesize + blocksize)
     check(deque("a" * (BLOCKLEN // 2)), basesize + blocksize)
     check(deque("a" * (BLOCKLEN // 2 + 1)), basesize + 2 * blocksize)
     check(deque("a" * (42 * BLOCKLEN)), basesize + 43 * blocksize)
开发者ID:alfonsodiecko,项目名称:PYTHON_DIST,代码行数:11,代码来源:test_deque.py


示例6: test_pickler

 def test_pickler(self):
     basesize = support.calcobjsize('5P2n3i2n3iP')
     p = _pickle.Pickler(io.BytesIO())
     self.assertEqual(object.__sizeof__(p), basesize)
     MT_size = struct.calcsize('3nP0n')
     ME_size = struct.calcsize('Pn0P')
     check = self.check_sizeof
     check(p, basesize +
         MT_size + 8 * ME_size +  # Minimal memo table size.
         sys.getsizeof(b'x'*4096))  # Minimal write buffer size.
     for i in range(6):
         p.dump(chr(i))
     check(p, basesize +
         MT_size + 32 * ME_size +  # Size of memo table required to
                                   # save references to 6 objects.
         0)  # Write buffer is cleared after every dump().
开发者ID:LPRD,项目名称:build_tools,代码行数:16,代码来源:test_pickle.py


示例7: test_unpickler

        def test_unpickler(self):
            basesize = support.calcobjsize('2Pn2P 2P2n2i5P 2P3n6P2n2i')
            unpickler = _pickle.Unpickler
            P = struct.calcsize('P')  # Size of memo table entry.
            n = struct.calcsize('n')  # Size of mark table entry.
            check = self.check_sizeof
            for encoding in 'ASCII', 'UTF-16', 'latin-1':
                for errors in 'strict', 'replace':
                    u = unpickler(io.BytesIO(),
                                  encoding=encoding, errors=errors)
                    self.assertEqual(object.__sizeof__(u), basesize)
                    check(u, basesize +
                             32 * P +  # Minimal memo table size.
                             len(encoding) + 1 + len(errors) + 1)

            stdsize = basesize + len('ASCII') + 1 + len('strict') + 1
            def check_unpickler(data, memo_size, marks_size):
                dump = pickle.dumps(data)
                u = unpickler(io.BytesIO(dump),
                              encoding='ASCII', errors='strict')
                u.load()
                check(u, stdsize + memo_size * P + marks_size * n)

            check_unpickler(0, 32, 0)
            # 20 is minimal non-empty mark stack size.
            check_unpickler([0] * 100, 32, 20)
            # 128 is memo table size required to save references to 100 objects.
            check_unpickler([chr(i) for i in range(100)], 128, 20)
            def recurse(deep):
                data = 0
                for i in range(deep):
                    data = [data, data]
                return data
            check_unpickler(recurse(0), 32, 0)
            check_unpickler(recurse(1), 32, 20)
            check_unpickler(recurse(20), 32, 58)
            check_unpickler(recurse(50), 64, 58)
            check_unpickler(recurse(100), 128, 134)

            u = unpickler(io.BytesIO(pickle.dumps('a', 0)),
                          encoding='ASCII', errors='strict')
            u.load()
            check(u, stdsize + 32 * P + 2 + 1)
开发者ID:LPRD,项目名称:build_tools,代码行数:43,代码来源:test_pickle.py


示例8: setUp

 def setUp(self):
     self.elementsize = support.calcobjsize('5P')
     # extra
     self.extra = struct.calcsize('PiiP4P')
开发者ID:chidea,项目名称:GoPythonDLLWrapper,代码行数:4,代码来源:test_xml_etree_c.py


示例9: check_sizeof

 def check_sizeof(self, format_str, number_of_codes):
     # The size of 'PyStructObject'
     totalsize = support.calcobjsize('2n3P')
     # The size taken up by the 'formatcode' dynamic array
     totalsize += struct.calcsize('P3n0P') * (number_of_codes + 1)
     support.check_sizeof(self, struct.Struct(format_str), totalsize)
开发者ID:M31MOTH,项目名称:cpython,代码行数:6,代码来源:test_struct.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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