Skip to content

Commit 596acb8

Browse files
committed
pypy
1 parent 1514705 commit 596acb8

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

scripts/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
networkx
2+
sympy
3+
curtsies
4+
shapely

scripts/runall.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
LANGUAGES = {
3535
"Python": "{year}/day{day}/day{day}.py",
36+
"PyPy": "{year}/day{day}/day{day}.py",
3637
"Rust": "{year}/target/release/day{day}",
3738
"C": "{year}/build/day{day}_c",
3839
"C++": "{year}/build/day{day}_cpp",
@@ -63,13 +64,13 @@ def save_cache():
6364
print(f"{FEINT}{ITALIC}cache commited{RESET}")
6465

6566

66-
def check_cache(key, file_timestamp: Path):
67+
def check_cache(key, file_timestamp: Path, no_check=False):
6768
cache = get_cache()
6869
key = str(key)
6970
e = cache.get(key, None)
7071
if e:
7172
timestamp = file_timestamp.stat().st_mtime_ns
72-
if e["timestamp"] == timestamp:
73+
if e["timestamp"] == timestamp or no_check:
7374
return e
7475
else:
7576
seconds = round((timestamp - e["timestamp"]) / 1000000000)
@@ -94,24 +95,30 @@ def update_cache(key, timestamp: Path, elapsed, status, answers):
9495
return e
9596

9697

97-
def run(key: str, prog: Path, file: Path, solution: t.List, refresh: bool):
98+
def run(key: str, prog: Path, lang: str, file: Path, solution: t.List, refresh: bool, dry_run: bool):
9899
if not prog.is_file():
99100
return
100101

101-
prog = prog.absolute()
102+
cmd = [prog.absolute().as_posix()]
103+
104+
if lang == "Python":
105+
cmd.insert(0, "python3")
106+
elif lang == "PyPy":
107+
cmd.insert(0, "pypy3")
102108

103109
if refresh:
104110
e = None
105111
else:
106-
e = check_cache(key, prog)
107-
112+
e = check_cache(key, prog, dry_run)
113+
if dry_run and not e:
114+
return None
108115
if e:
109116
in_cache = True
110117
else:
111118
in_cache = False
112119

113120
start = time.time_ns()
114-
out = subprocess.run([prog, file.absolute()], cwd=prog.parent, stdout=subprocess.PIPE)
121+
out = subprocess.run(cmd + [file.absolute()], stdout=subprocess.PIPE)
115122
elapsed = time.time_ns() - start
116123
answers = out.stdout.decode().strip()
117124

@@ -209,7 +216,7 @@ def load_data(filter_year):
209216

210217

211218
def run_day(
212-
year: int, day: int, mday: str, day_inputs: t.Dict, day_sols: t.Dict, problems: t.Set, filter_lang, refresh
219+
year: int, day: int, mday: str, day_inputs: t.Dict, day_sols: t.Dict, problems: t.Set, filter_lang, refresh, dry_run
213220
):
214221
elapsed = defaultdict(list)
215222

@@ -241,7 +248,7 @@ def run_day(
241248
first = False
242249
subprocess.call([prog, "--help"], stdout=subprocess.DEVNULL)
243250

244-
e = run(key, prog, file, day_sols.get(crc), refresh)
251+
e = run(key, prog, lang, file, day_sols.get(crc), refresh, dry_run)
245252

246253
if not e:
247254
continue
@@ -281,15 +288,17 @@ def run_day(
281288
problems.append(line)
282289

283290
nb_samples = set(len(t) for _, t in elapsed.items())
284-
assert len(nb_samples) == 1
291+
assert len(nb_samples) == 1 or len(nb_samples) == 0
292+
nb_samples = 0 if len(nb_samples) == 0 else nb_samples.pop()
285293

286-
return dict((lang, sum(t) / len(t)) for lang, t in elapsed.items()), nb_samples.pop()
294+
return dict((lang, sum(t) / len(t)) for lang, t in elapsed.items()), nb_samples
287295

288296

289297
def main():
290298
parser = argparse.ArgumentParser()
291299
parser.add_argument("-l", "--language", type=str, metavar="LANG", help="filter by language")
292300
parser.add_argument("-r", "--refresh", action="store_true", help="relaunch solutions")
301+
parser.add_argument("-n", "--dry-run", action="store_true", help="do not run")
293302
parser.add_argument("n", type=int, nargs="*", help="filter by year or year/day")
294303

295304
args = parser.parse_args()
@@ -320,7 +329,15 @@ def main():
320329
mday = mday.name.removeprefix("day")
321330

322331
elapsed, nb_samples = run_day(
323-
year, day, mday, inputs[year, day], sols[year, day], problems, args.language, args.refresh
332+
year,
333+
day,
334+
mday,
335+
inputs[year, day],
336+
sols[year, day],
337+
problems,
338+
args.language,
339+
args.refresh,
340+
args.dry_run,
324341
)
325342
save_cache()
326343

@@ -344,8 +361,8 @@ def main():
344361
except KeyboardInterrupt:
345362
pass
346363

347-
except Exception as e:
348-
print(f"{RED}ERROR {e}{RESET}")
364+
# except Exception as e:
365+
# print(f"{RED}ERROR {e}{RESET}")
349366

350367
finally:
351368
if stats_elapsed:

0 commit comments

Comments
 (0)