Created
March 8, 2021 07:24
-
-
Save amaciel81/8814dbefc864ec434d03cf61d02e36ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Process | |
def multithread_scheduler(instances: int, worker: Callable, args: List[Any]) -> None: | |
threads = [ | |
Thread(target=worker, args=args) | |
for _ in range(instances) | |
] | |
for thread in threads: | |
thread.start() | |
for thread in threads: | |
thread.join() | |
print("Multithread Execution, CPU bound") | |
with timer(): | |
multithread_scheduler(8, cpu_worker, [10_000_000, 49]) | |
print("Multithread Execution, I/O bound") | |
with timer(): | |
multithread_scheduler(8, io_worker, [3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment