Skip to content

Instantly share code, notes, and snippets.

@dichharai
Last active November 7, 2022 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dichharai/598f6785a62641b90de6782a5092c2fd to your computer and use it in GitHub Desktop.
Save dichharai/598f6785a62641b90de6782a5092c2fd to your computer and use it in GitHub Desktop.
from threading import Thread
from time import perf_counter
def sum_up_to(start: int, end: int):
total = 0
print('start...')
for i in range(start, end):
total += i
print('end...')
print(f'sum from {start}..{end} is {total}.')
if __name__ == "__main__":
start = perf_counter()
t1 = Thread(target=sum_up_to, args=(1, 5_000))
t2 = Thread(target=sum_up_to, args=(5_001, 10_000))
t1.start()
t2.start()
t1.join()
t2.join()
print(f'Took {perf_counter() - start:.6f} seconds.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment