Python dummy function with specific amount of ram for workflow testing

Viewed 60

I want to create a dummy workflow for testing a workflow managing software.

Is there a python function where I can say how much RAM it must use? So I can make multiple workflows, all needing a different amount of RAM.

Else, do you know good dummy workflows I can use?

2 Answers

A modified version of code from here: https://askubuntu.com/a/301063/1102943

Code (python3):

import numpy

def take_up_ram(gigabytes):
    n = gigabytes * 1024
    result = [numpy.random.bytes(1024*1024) for x in range(n)]
    print(len(result))

Simply create any primitive type of desired size:

>>> import sys
>>> sys.getsizeof(bytes(1024 * 1024))
1048609

Note that by the nature of how Python works, no method will exactly set the memory consumption. The overhead should be roughly constant and negligible for all significant sizes, though.

Related