-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_task_np.py
54 lines (33 loc) · 1.12 KB
/
simple_task_np.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
36
37
38
39
40
41
42
43
44
45
46
47
import functools
import time
import unittest
import heapq
import random
import numpy as np
def count_time(func):
@functools.wraps(func)
def inner(*args, **kwargs):
t = time.time()
result = func(*args, **kwargs)
time_of_work = time.time() - t
print('time_of_work = ', time_of_work)
return result
return inner
@count_time
def totalTime(input_array, number_of_items):
result_array = [0] * number_of_items
for item in input_array:
heapq.heapreplace(result_array, result_array[0] + item)
return heapq.nlargest(1, result_array)[0]
def get_random_array_generator(low, high, size):
return (random.randint(low, high) for i in range(size))
def get_np_random_array_generator(low, high, size):
return (np.random.randint(low, high) for i in range(size))
if __name__ == '__main__':
low = 1
high = 256
queue_size = 10000000
number_of_cash_desk = 1000
current_queue = list(get_np_random_array_generator(low, high, queue_size))
result = totalTime(current_queue, number_of_cash_desk)
print('result = ', result)