forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2.py
35 lines (27 loc) ยท 1.09 KB
/
2.py
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
from random import randint
import time
# ๋ฐฐ์ด์ 10,000๊ฐ์ ์ ์๋ฅผ ์ฝ์
array = []
for _ in range(10000):
array.append(randint(1, 100)) # 1๋ถํฐ 100 ์ฌ์ด์ ๋๋คํ ์ ์
# ์ ํ ์ ๋ ฌ ํ๋ก๊ทธ๋จ ์ฑ๋ฅ ์ธก์
start_time = time.time()
# ์ ํ ์ ๋ ฌ ํ๋ก๊ทธ๋จ ์์ค์ฝ๋
for i in range(len(array)):
min_index = i # ๊ฐ์ฅ ์์ ์์์ ์ธ๋ฑ์ค
for j in range(i + 1, len(array)):
if array[min_index] > array[j]:
min_index = j
array[i], array[min_index] = array[min_index], array[i] # ์ค์ํ
end_time = time.time() # ์ธก์ ์ข
๋ฃ
print("์ ํ ์ ๋ ฌ ์ฑ๋ฅ ์ธก์ :", end_time - start_time) # ์ํ ์๊ฐ ์ถ๋ ฅ
# ๋ฐฐ์ด์ ๋ค์ ๋ฌด์์ ๋ฐ์ดํฐ๋ก ์ด๊ธฐํ
array = []
for _ in range(10000):
array.append(randint(1, 100)) # 1๋ถํฐ 100 ์ฌ์ด์ ๋๋คํ ์ ์
# ๊ธฐ๋ณธ ์ ๋ ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฑ๋ฅ ์ธก์
start_time = time.time()
# ๊ธฐ๋ณธ ์ ๋ ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ
array.sort()
end_time = time.time() # ์ธก์ ์ข
๋ฃ
print("๊ธฐ๋ณธ ์ ๋ ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฑ๋ฅ ์ธก์ :", end_time - start_time) # ์ํ ์๊ฐ ์ถ๋ ฅ