Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python dummy function with specific amount of ram for workflow testing

Tags:

python

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?

like image 937
Kingvinst Avatar asked Mar 01 '26 18:03

Kingvinst


2 Answers

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.

like image 141
MisterMiyagi Avatar answered Mar 04 '26 06:03

MisterMiyagi


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))
like image 42
KetZoomer Avatar answered Mar 04 '26 08:03

KetZoomer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!