Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from multiprocessing import Pool
- def cpu_task(n):
- total = 0
- for i in range(n):
- total += i**2
- return total
- if __name__ == "__main__":
- start = time.time()
- with Pool(4) as pool:
- results = pool.map(cpu_task, [10_000_000] * 4)
- end = time.time()
- print(f"Execution Time: {end - start:.2f} seconds")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement