change chunk size and remove infinit loop
This commit is contained in:
parent
34b9e54c0f
commit
d7ef53e747
@ -6,6 +6,7 @@ text: str = open("input.txt", "r").read()
|
|||||||
_value: int = 0
|
_value: int = 0
|
||||||
|
|
||||||
_lines = text.splitlines()
|
_lines = text.splitlines()
|
||||||
|
CHUNK_SIZE = 100000000
|
||||||
|
|
||||||
current_ranges = []
|
current_ranges = []
|
||||||
convertions = []
|
convertions = []
|
||||||
@ -39,7 +40,6 @@ for i, line in enumerate(_lines):
|
|||||||
if (line.endswith(" map:")):
|
if (line.endswith(" map:")):
|
||||||
convertions.append(extract_map_data(_lines[i + 1:]))
|
convertions.append(extract_map_data(_lines[i + 1:]))
|
||||||
|
|
||||||
|
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
def display_duration(interval_between_call, nb_total_values):
|
def display_duration(interval_between_call, nb_total_values):
|
||||||
global current_time
|
global current_time
|
||||||
@ -57,6 +57,8 @@ def get_min_in_range(lst_conversions, start, stop):
|
|||||||
min_value = do_all_convertions(lst_conversions, start)
|
min_value = do_all_convertions(lst_conversions, start)
|
||||||
i = start + 1;
|
i = start + 1;
|
||||||
while (i != stop):
|
while (i != stop):
|
||||||
|
if ((i - start) % 1000000 == 0):
|
||||||
|
print(f"{int((i - start)/(stop - start))}% ({i - start}/{stop - start})")
|
||||||
value = do_all_convertions(lst_conversions, i)
|
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)
|
min_value = min(value, min_value)
|
||||||
@ -69,7 +71,6 @@ def thread_process(convertions, start_value, chunk):
|
|||||||
global values
|
global values
|
||||||
values.append(get_min_in_range(convertions, start_value, chunk))
|
values.append(get_min_in_range(convertions, start_value, chunk))
|
||||||
|
|
||||||
CHUNK_SIZE = 10000000
|
|
||||||
for current_range in current_ranges:
|
for current_range in current_ranges:
|
||||||
print("new range")
|
print("new range")
|
||||||
start, stop = current_range
|
start, stop = current_range
|
||||||
@ -86,12 +87,13 @@ for current_range in current_ranges:
|
|||||||
while (i < len(chunks)):
|
while (i < len(chunks)):
|
||||||
t = threading.Thread(target=thread_process, args=(convertions, start_value, chunks[i]))
|
t = threading.Thread(target=thread_process, args=(convertions, start_value, chunks[i]))
|
||||||
t.start()
|
t.start()
|
||||||
print(f"start thread{i}/{len(chunks) - 1}")
|
print(f"start thread{i + 1}/{len(chunks)}")
|
||||||
i += 1
|
i += 1
|
||||||
start_value = chunks[i - 1]
|
start_value = chunks[i - 1]
|
||||||
|
|
||||||
while (True):
|
while (threading.active_count() != 1):
|
||||||
print(len(values))
|
print(values, threading.active_count() - 1)
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
_value = min(values)
|
_value = min(values)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user