add: multhread
This commit is contained in:
parent
4d2161f5b1
commit
bf896841d2
@ -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,19 +57,19 @@ 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))
|
||||
min_value = min(value, min_value)
|
||||
i += 1
|
||||
return (min_value)
|
||||
|
||||
CHUNK_SIZE = 10
|
||||
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
|
||||
i = start
|
||||
@ -83,7 +83,10 @@ for current_range in current_ranges:
|
||||
start_value = start
|
||||
i = 0
|
||||
while (i < len(chunks)):
|
||||
values.append(get_min_in_range(convertions, start_value, chunks[i]))
|
||||
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]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user