Compare commits

...

2 Commits

Author SHA1 Message Date
bf896841d2 add: multhread 2023-12-05 10:49:36 +01:00
4d2161f5b1 use chunk to prepare multhread 2023-12-05 10:37:17 +01:00

View File

@ -1,7 +1,7 @@
import threading
import time
text: str = open("example.txt", "r").read()
text: str = open("input.txt", "r").read()
_value: int = 0
@ -57,22 +57,39 @@ def get_min_in_range(lst_conversions, start, stop):
min_value = do_all_convertions(lst_conversions, start)
i = start + 1;
while (i != stop):
if ((i - start) % 10000 == 0):
display_duration(10000, stop - start)
print(i - start, '/', stop - start)
value = do_all_convertions(lst_conversions, i)
print(min_value, value, min(value, min_value))
#print(min_value, value, min(value, min_value))
min_value = min(value, min_value)
i += 1
return (min_value)
_min = 2000000000000000000
values = []
def thread_process(convertions, start_value, chunk):
global values
values.append(get_min_in_range(convertions, start_value, chunk))
CHUNK_SIZE = 10
for current_range in current_ranges:
start, stop = current_range
_min = min(_min, get_min_in_range(convertions, start, stop))
i = start
chunks = []
while(i < stop):
i += CHUNK_SIZE
if (i >= stop):
chunks.append(stop)
else:
chunks.append(i)
start_value = start
i = 0
while (i < len(chunks)):
t = threading.Thread(target=thread_process, args=(convertions, start_value, chunks[i]))
t.start()
display_duration(1, len(chunks))
print(i, '/', len(chunks))
i += 1
start_value = chunks[i - 1]
_value = _min
_value = min(values)
print(_value)