-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy_ad_3_6.py
More file actions
51 lines (35 loc) · 929 Bytes
/
py_ad_3_6.py
File metadata and controls
51 lines (35 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Section 3
Concurrency, CPU Bound vs I/O Bound - CPU Bound(1) - Synchronous
Keyword - CPU Bound
"""
# CPU-Bound 예제(https://realpython.com/python-concurrency/#synchronous-version)
import time
# 실행함수1(계산)
def cpu_bound(number):
return sum(i * i for i in range(number))
# 실행함수2
def find_sums(numbers):
result = []
for number in numbers:
result.append(cpu_bound(number))
return result
def main():
numbers = [3_000_000 + x for x in range(30)]
# 확인
# print(numbers)
# 실행시간 측정
start_time = time.time()
# 실행
total = find_sums(numbers)
print()
# 결과 출력
print(f"Total list : {total}")
print(f"Sum : {sum(total)}")
# 실행 시간 종료
duration = time.time() - start_time
print()
# 수행 시간
print(f"Duration : {duration} seconds")
if __name__ == "__main__":
main()