mirror of
https://github.com/iritmaximus/tira.git
synced 2026-10-12 19:13:47 +03:00
39 lines
698 B
Python
39 lines
698 B
Python
from random import shuffle, randint
|
|
from time import time
|
|
from heapq import heapify, heappop
|
|
|
|
n = 10**6
|
|
list = [randint(1, 10**9) for x in range(n)]
|
|
shuffle(list)
|
|
|
|
|
|
def main():
|
|
start_time_1 = time()
|
|
sorted_list = sorted(list)
|
|
shorter_list = sorted_list[: n // 10]
|
|
sum1 = 0
|
|
for x in shorter_list:
|
|
sum1 += x
|
|
end_time_1 = time()
|
|
print(end_time_1 - start_time_1, sum1)
|
|
|
|
start_time_2 = time()
|
|
sum2 = 0
|
|
|
|
heapify(list)
|
|
|
|
for x in range(0, n // 10):
|
|
sum2 += list[0]
|
|
heappop(list)
|
|
|
|
end_time_2 = time()
|
|
|
|
print(end_time_2 - start_time_2, sum2)
|
|
|
|
print(sorted_list[:10])
|
|
print(list[:10])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|