mpetests.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:PyExPool 作者: eXascaleInfolab 项目源码 文件源码
def allocDelayProg(size, duration):
    """Python program as str that allocates object of the specified size
    in Gigabytes and then waits for the specified time

    size  - allocation size, bytes; None to skip allocation
    duration  - execution duration, sec; None to skip the sleep

    return  - Python program as str
    """
    return """from __future__ import print_function, division  # Required for stderr output, must be the first import
import sys
import time
import array

if {size} is not None:
    a = array.array('b', [0])
    asize = sys.getsizeof(a)
    # Note: allocate at least empty size, i.e. empty list
    buffer = a * int(max({size} - asize + 1, 0))
    #if _DEBUG_TRACE:
    # print(''.join(('  allocDelayProg(), allocated ', str(sys.getsizeof(buffer))
    #   , ' bytes for ', str({duration}),' sec')), file=sys.stderr)
if {duration} is not None:
    time.sleep({duration})
""".format(size=size, duration=duration)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号