Skip to content

Instantly share code, notes, and snippets.

@Mehran1022mm
Created November 30, 2024 18:07
Show Gist options
  • Save Mehran1022mm/6afe4cf2ab43e444aa8e7e450293f3aa to your computer and use it in GitHub Desktop.
Save Mehran1022mm/6afe4cf2ab43e444aa8e7e450293f3aa to your computer and use it in GitHub Desktop.
designed to maximize the usage of CPU and memory resources.
import threading
import numpy as np
import multiprocessing
import os
def cpu_stress():
while True:
_ = sum(i * i * i * i * i * i * i * i for i in range(10**12))
def memory_stress():
allocated_memory = []
while True:
allocated_memory.append(np.ones((65536, 65536), dtype=np.float64))
def stress_test():
cpu_cores = multiprocessing.cpu_count()
memory_threads = cpu_cores // 2
cpu_threads = cpu_cores - memory_threads
threads = []
for _ in range(cpu_threads):
thread_cpu = threading.Thread(target=cpu_stress)
threads.append(thread_cpu)
thread_cpu.start()
for _ in range(memory_threads):
thread_memory = threading.Thread(target=memory_stress)
threads.append(thread_memory)
thread_memory.start()
for thread in threads:
thread.join()
if __name__ == "__main__":
stress_test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment