Skip to content

Commit

Permalink
[김필모] 9주차 미션 제출 (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
why-arong authored Jul 6, 2024
1 parent 849c02e commit 6afa3e7
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions 8th_members/김필모/9주차.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
```python3
import time
from multiprocessing import Pool

# Define the CPU-bound task


def cpu_bound_task(n):
result = 1
for i in range(1, n + 1):
result *= i
return result

# Single-process version


def single_process(tasks):
results = []
for task in tasks:
results.append(cpu_bound_task(task))
return results

# Multiprocessing version


def multi_process(tasks):
with Pool() as pool:
results = pool.map(cpu_bound_task, tasks)
return results


if __name__ == "__main__":
tasks = [100000 + i for i in range(20)] # Define tasks

start = time.time()
single_process(tasks)
print("Single-process time:", time.time() - start)

start = time.time()
multi_process(tasks)
print("Multiprocessing time:", time.time() - start)
```
<img width="866" alt="Screenshot 2024-06-30 at 2 18 40 PM" src="https://github.com/why-arong/CPython-Guide/assets/68311908/90adfdba-2fcb-491e-a7ba-e95e32c61e36">

0 comments on commit 6afa3e7

Please sign in to comment.