Report elapsed time

This commit is contained in:
Mattéo Delabre 2021-01-27 19:34:28 +01:00
parent d77b88ef9f
commit a653a90ad1
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
1 changed files with 6 additions and 3 deletions

View File

@ -3,6 +3,7 @@ from functools import partial
from itertools import product from itertools import product
from multiprocessing import Pool from multiprocessing import Pool
from subprocess import DEVNULL, PIPE, Popen, TimeoutExpired from subprocess import DEVNULL, PIPE, Popen, TimeoutExpired
from time import time
from typing import List from typing import List
chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ ' chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ '
@ -106,9 +107,8 @@ def find_script(
:returns: list of matching scripts :returns: list of matching scripts
""" """
candidates = [] candidates = []
bound_check_script = partial(check_script, pairs, timeout)
out_invalid = [] out_invalid = []
bound_check_script = partial(check_script, pairs, timeout)
for i in range(max_length + 1): for i in range(max_length + 1):
out_invalid.append(open(invalid_prefix + str(i), "w")) out_invalid.append(open(invalid_prefix + str(i), "w"))
@ -116,6 +116,7 @@ def find_script(
chars_count = len(chars) chars_count = len(chars)
num_tasks = int((chars_count ** (max_length + 1) - 1) / (chars_count - 1)) num_tasks = int((chars_count ** (max_length + 1) - 1) / (chars_count - 1))
done_tasks = 0 done_tasks = 0
start_time = time()
with Pool(processes) as pool: with Pool(processes) as pool:
for script, status in pool.imap_unordered( for script, status in pool.imap_unordered(
@ -128,7 +129,8 @@ def find_script(
if done_tasks % 10000 == 0: if done_tasks % 10000 == 0:
print( print(
f"Progress: {done_tasks}/{num_tasks} \ f"Progress: {done_tasks}/{num_tasks} \
{done_tasks / num_tasks * 100:.1f}%", {done_tasks / num_tasks * 100:.1f}% \
(running for {time() - start_time:.1f}s)",
file=out_log, flush=True file=out_log, flush=True
) )
@ -145,4 +147,5 @@ def find_script(
for file in out_invalid: for file in out_invalid:
file.close() file.close()
print(f"Finished in {time() - start_time:.1f}s", file=out_log, flush=True)
return candidates return candidates