You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
412 B
Python

# cpu bound programm
from threading import Thread
import time
def count(n):
while n > 0:
n -= 1
# series run
t0 = time.time()
count(100_000_000)
count(100_000_000)
print(time.time() - t0)
# parallel run
t0 = time.time()
th1 = Thread(target=count, args=(100_000_000,))
th2 = Thread(target=count, args=(100_000_000,))
th1.start(); th2.start()
th1.join(); th2.join()
print(time.time() - t0)