Advertisement
Jexal

b054c342-1cf4-45ae-aec8-735bdde3957f

Jan 19th, 2025
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. import time
  2. from multiprocessing import Pool
  3.  
  4. def cpu_task(n):
  5.     total = 0
  6.     for i in range(n):
  7.         total += i**2
  8.     return total
  9.  
  10. if __name__ == "__main__":
  11.     start = time.time()
  12.     with Pool(4) as pool:
  13.         results = pool.map(cpu_task, [10_000_000] * 4)
  14.     end = time.time()
  15.  
  16.     print(f"Execution Time: {end - start:.2f} seconds")
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement