adventofcode 25.8__tar.gz → 25.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {adventofcode-25.8 → adventofcode-25.10}/CHANGELOG.md +43 -0
- {adventofcode-25.8 → adventofcode-25.10}/PKG-INFO +6 -2
- {adventofcode-25.8 → adventofcode-25.10}/README.md +5 -1
- adventofcode-25.10/src/adventofcode/__about__.py +1 -0
- {adventofcode-25.8 → adventofcode-25.10}/src/adventofcode/cli.py +258 -48
- adventofcode-25.8/src/adventofcode/__about__.py +0 -1
- {adventofcode-25.8 → adventofcode-25.10}/.github/workflows/publish.yml +0 -0
- {adventofcode-25.8 → adventofcode-25.10}/.gitignore +0 -0
- {adventofcode-25.8 → adventofcode-25.10}/.pre-commit-config.yaml +0 -0
- {adventofcode-25.8 → adventofcode-25.10}/LICENSE +0 -0
- {adventofcode-25.8 → adventofcode-25.10}/pyproject.toml +0 -0
- {adventofcode-25.8 → adventofcode-25.10}/screenshot.png +0 -0
- {adventofcode-25.8 → adventofcode-25.10}/src/__init__.py +0 -0
- {adventofcode-25.8 → adventofcode-25.10}/src/adventofcode/__init__.py +0 -0
- {adventofcode-25.8 → adventofcode-25.10}/src/adventofcode/utils.py +0 -0
- {adventofcode-25.8 → adventofcode-25.10}/tests/__init__.py +0 -0
- {adventofcode-25.8 → adventofcode-25.10}/tests/test_adventofcode.py +0 -0
|
@@ -5,6 +5,49 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Calendar Versioning](https://calver.org).
|
|
7
7
|
|
|
8
|
+
## [25.10]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
* When you have alternative solutions only the fastest one is now counted in the totals row and the display in the table was improved:
|
|
13
|
+
|
|
14
|
+
| Day | Variant | Status | Part 1 Time | Part 2 Time | Total Time |
|
|
15
|
+
|----:|:--------|:------:|------------:|------------:|-----------:|
|
|
16
|
+
| 01 | | ✅ | 0.54ms 🟢 | 0.63ms 🟢 | 1.17ms 🟢 |
|
|
17
|
+
| 02 | | ✅ | 0.08ms 🟢 | 0.13ms 🟢 | 0.21ms 🟢 |
|
|
18
|
+
| 03 | | ✅ | 0.38ms 🟢 | 0.98ms 🟢 | 1.36ms 🟢 |
|
|
19
|
+
| 04 | numpy | ✅ | 0.80ms 🟢 | 4.48ms 🟢 | 5.28ms 🟢 |
|
|
20
|
+
| ~~04~~ | | ✅ | 5.87ms ⚪ | 14.37ms ⚪ | 20.24ms ⚪ |
|
|
21
|
+
| 05 | | ✅ | 0.28ms 🟢 | 0.09ms 🟢 | 0.37ms 🟢 |
|
|
22
|
+
| 06 | | ✅ | 0.79ms 🟢 | 1.25ms 🟢 | 2.04ms 🟢 |
|
|
23
|
+
| 07 | | ✅ | 1.21ms 🟢 | 1.43ms 🟢 | 2.64ms 🟢 |
|
|
24
|
+
| 08 | | 🕑 | - | - | - |
|
|
25
|
+
| 09 | | 🕑 | - | - | - |
|
|
26
|
+
| 10 | | 🕑 | - | - | - |
|
|
27
|
+
| 11 | | 🕑 | - | - | - |
|
|
28
|
+
| 12 | | 🕑 | - | - | - |
|
|
29
|
+
| **Total** | | | 4.08ms 🟢 | 8.99ms 🟢 | 13.07ms 🟢 |
|
|
30
|
+
|
|
31
|
+
Legend:
|
|
32
|
+
* 🟢 < 100ms
|
|
33
|
+
* 🟡 100ms - 1s
|
|
34
|
+
* 🔴 > 1s
|
|
35
|
+
* ⚪ Not included in total
|
|
36
|
+
|
|
37
|
+
## Fixed
|
|
38
|
+
|
|
39
|
+
* Fix benchmark help text (by @baloncek2662)
|
|
40
|
+
|
|
41
|
+
## [25.9]
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
* Ability to benchmark a single file. Thank you @baloncek2662 ❤️
|
|
46
|
+
|
|
47
|
+
### Fixed
|
|
48
|
+
|
|
49
|
+
* Crash on Windows. Thank you @tfs-sean-disanti ❤️
|
|
50
|
+
|
|
8
51
|
## [25.8]
|
|
9
52
|
|
|
10
53
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: adventofcode
|
|
3
|
-
Version: 25.
|
|
3
|
+
Version: 25.10
|
|
4
4
|
Summary: Helper utilities for solving Advent of Code puzzles
|
|
5
5
|
Project-URL: Documentation, https://github.com/anze3db/adventofcode#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/anze3db/adventofcode/issues
|
|
@@ -163,9 +163,13 @@ uv run adventofcode benchmark
|
|
|
163
163
|
|
|
164
164
|
This will run each day's solution and parse the timing results from the output. The results will be printed to the console as well as added to your README.md.
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
If you are in a hurry you can also benchmark a single day's solution with
|
|
167
167
|
|
|
168
|
+
```shell
|
|
169
|
+
uv run adventofcode benchmark 05.py
|
|
170
|
+
```
|
|
168
171
|
|
|
172
|
+
Example console output:
|
|
169
173
|
|
|
170
174
|
Example README:
|
|
171
175
|
|
|
@@ -134,9 +134,13 @@ uv run adventofcode benchmark
|
|
|
134
134
|
|
|
135
135
|
This will run each day's solution and parse the timing results from the output. The results will be printed to the console as well as added to your README.md.
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
If you are in a hurry you can also benchmark a single day's solution with
|
|
138
138
|
|
|
139
|
+
```shell
|
|
140
|
+
uv run adventofcode benchmark 05.py
|
|
141
|
+
```
|
|
139
142
|
|
|
143
|
+
Example console output:
|
|
140
144
|
|
|
141
145
|
Example README:
|
|
142
146
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "25.10"
|
|
@@ -66,7 +66,7 @@ def init_templates(year: int, output_dir: Path, num_days: int) -> None:
|
|
|
66
66
|
console.log(f"Skipping {filename} (already exists)")
|
|
67
67
|
continue
|
|
68
68
|
|
|
69
|
-
filepath.write_text(TEMPLATE.format(day=day, year=year))
|
|
69
|
+
filepath.write_text(TEMPLATE.format(day=day, year=year), encoding="utf-8")
|
|
70
70
|
console.log(f"Created {filename}")
|
|
71
71
|
|
|
72
72
|
gitignore_path = output_dir / ".gitignore"
|
|
@@ -92,7 +92,8 @@ def init_templates(year: int, output_dir: Path, num_days: int) -> None:
|
|
|
92
92
|
"# You can find it in your browser's developer tools after logging in to adventofcode.com. \n"
|
|
93
93
|
"# The name of the cookie is `session`.\n"
|
|
94
94
|
'AOC_SESSION=""\n'
|
|
95
|
-
f"AOC_YEAR={year}\n"
|
|
95
|
+
f"AOC_YEAR={year}\n",
|
|
96
|
+
encoding="utf-8",
|
|
96
97
|
)
|
|
97
98
|
console.log("Created .env file (remember to set your AOC_SESSION)")
|
|
98
99
|
|
|
@@ -128,12 +129,15 @@ Color = Literal["green", "yellow", "red", "white"]
|
|
|
128
129
|
@dataclass
|
|
129
130
|
class DayResult:
|
|
130
131
|
day: str
|
|
132
|
+
day_num: str = ""
|
|
133
|
+
variant: str = ""
|
|
131
134
|
part1_time: float = 0.0
|
|
132
135
|
part2_time: float = 0.0
|
|
133
136
|
total_time: float = 0.0
|
|
134
137
|
|
|
135
138
|
status: str = ""
|
|
136
139
|
error: str | None = None
|
|
140
|
+
in_total: bool = True
|
|
137
141
|
|
|
138
142
|
|
|
139
143
|
def time_to_color(seconds: float) -> Color:
|
|
@@ -147,13 +151,30 @@ def time_to_color(seconds: float) -> Color:
|
|
|
147
151
|
return "red"
|
|
148
152
|
|
|
149
153
|
|
|
154
|
+
def split_day_name(day_name: str) -> tuple[str, str]:
|
|
155
|
+
"""Split a day name into (day_number, variant).
|
|
156
|
+
|
|
157
|
+
Examples:
|
|
158
|
+
'01' -> ('01', '')
|
|
159
|
+
'01-alt' -> ('01', 'alt')
|
|
160
|
+
'03-numpy' -> ('03', 'numpy')
|
|
161
|
+
"""
|
|
162
|
+
match = re.match(r"(\d\d)(?:-(.+))?", day_name)
|
|
163
|
+
if match:
|
|
164
|
+
day_num = match.group(1)
|
|
165
|
+
variant = match.group(2) or ""
|
|
166
|
+
return day_num, variant
|
|
167
|
+
return day_name, ""
|
|
168
|
+
|
|
169
|
+
|
|
150
170
|
def run_day(filepath: Path) -> DayResult:
|
|
151
171
|
match = re.match(r"(\d\d)", filepath.stem)
|
|
152
172
|
day_num = int(match.group(1)) if match else 0
|
|
173
|
+
day_num_str, variant = split_day_name(filepath.stem)
|
|
153
174
|
if datetime.date(AOC_YEAR, 12, day_num) > today_est:
|
|
154
|
-
return DayResult(day=filepath.stem, status="🕑")
|
|
175
|
+
return DayResult(day=filepath.stem, day_num=day_num_str, variant=variant, status="🕑")
|
|
155
176
|
|
|
156
|
-
result = DayResult(day=filepath.stem)
|
|
177
|
+
result = DayResult(day=filepath.stem, day_num=day_num_str, variant=variant)
|
|
157
178
|
|
|
158
179
|
if "adventofcode run" in filepath.read_text():
|
|
159
180
|
command = ["adventofcode", "run", str(filepath), "--benchmark"]
|
|
@@ -206,36 +227,87 @@ def run_day(filepath: Path) -> DayResult:
|
|
|
206
227
|
|
|
207
228
|
def build_markdown_table(results: list[DayResult], total_time: float, total_part_1: float, total_part_2: float) -> str:
|
|
208
229
|
"""Generate a markdown table from benchmark results."""
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
230
|
+
# Check if any result has a variant
|
|
231
|
+
has_variants = any(r.variant for r in results)
|
|
232
|
+
|
|
233
|
+
if has_variants:
|
|
234
|
+
lines = [
|
|
235
|
+
"| Day | Variant | Status | Part 1 Time | Part 2 Time | Total Time | ",
|
|
236
|
+
"|----:|:--------|:------:|------------:|------------:|-----------:| ",
|
|
237
|
+
]
|
|
238
|
+
else:
|
|
239
|
+
lines = [
|
|
240
|
+
"| Day | Status | Part 1 Time | Part 2 Time | Total Time | ",
|
|
241
|
+
"|----:|:------:|------------:|------------:|-----------:| ",
|
|
242
|
+
]
|
|
213
243
|
|
|
214
244
|
for r in results:
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
245
|
+
if not r.in_total and r.total_time > 0:
|
|
246
|
+
p1_time = f"{format_time(r.part1_time)} ⚪"
|
|
247
|
+
p2_time = f"{format_time(r.part2_time)} ⚪"
|
|
248
|
+
total = f"{format_time(r.total_time)} ⚪"
|
|
249
|
+
day_display = f"~~{r.day_num}~~"
|
|
250
|
+
variant_display = f"~~{r.variant}~~" if r.variant else ""
|
|
251
|
+
else:
|
|
252
|
+
p1_time = markdown_color(format_time(r.part1_time), time_to_color(r.part1_time))
|
|
253
|
+
p2_time = markdown_color(format_time(r.part2_time), time_to_color(r.part2_time))
|
|
254
|
+
total = markdown_color(format_time(r.total_time), time_to_color(r.total_time))
|
|
255
|
+
day_display = r.day_num
|
|
256
|
+
variant_display = r.variant
|
|
257
|
+
|
|
258
|
+
if has_variants:
|
|
259
|
+
lines.append(f"| {day_display} | {variant_display} | {r.status} | {p1_time} | {p2_time} | {total} |")
|
|
260
|
+
else:
|
|
261
|
+
lines.append(f"| {day_display} | {r.status} | {p1_time} | {p2_time} | {total} |")
|
|
220
262
|
|
|
221
263
|
p1_total = markdown_color(format_time(total_part_1), time_to_color(total_part_1))
|
|
222
264
|
p2_total = markdown_color(format_time(total_part_2), time_to_color(total_part_2))
|
|
223
265
|
total = markdown_color(format_time(total_time), time_to_color(total_time))
|
|
224
266
|
# Add total row
|
|
225
|
-
|
|
267
|
+
if has_variants:
|
|
268
|
+
lines.append(f"| **Total** | | | {p1_total} | {p2_total} | {total} |")
|
|
269
|
+
else:
|
|
270
|
+
lines.append(f"| **Total** | | {p1_total} | {p2_total} | {total} |")
|
|
226
271
|
lines.append("")
|
|
227
272
|
lines.append("Legend:")
|
|
228
273
|
lines.append(" * 🟢 < 100ms")
|
|
229
274
|
lines.append(" * 🟡 100ms - 1s")
|
|
230
275
|
lines.append(" * 🔴 > 1s")
|
|
276
|
+
lines.append(" * ⚪ Not included in total")
|
|
231
277
|
return "\n".join(lines)
|
|
232
278
|
|
|
233
279
|
|
|
234
|
-
def
|
|
280
|
+
def get_result_row(table: str, pattern: str) -> str | None:
|
|
281
|
+
table_match = re.search(pattern, table, flags=re.MULTILINE)
|
|
282
|
+
return None if table_match is None else table_match.group(0)
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def get_time_diff(old_day_row: str, new_day_row: str) -> list[float]:
|
|
286
|
+
pattern = r"(\d+\.\d+)(ms|s)"
|
|
287
|
+
|
|
288
|
+
def parse_time(match: tuple[str, str]) -> float:
|
|
289
|
+
val = float(match[0])
|
|
290
|
+
return val * 1000 if match[1] == "s" else val
|
|
291
|
+
|
|
292
|
+
matches_old = re.findall(pattern, old_day_row)
|
|
293
|
+
matches_new = re.findall(pattern, new_day_row)
|
|
294
|
+
|
|
295
|
+
if len(matches_old) >= 2 and len(matches_new) >= 2:
|
|
296
|
+
part_1_time_old = parse_time(matches_old[0])
|
|
297
|
+
part_2_time_old = parse_time(matches_old[1])
|
|
298
|
+
|
|
299
|
+
part_1_time_new = parse_time(matches_new[0])
|
|
300
|
+
part_2_time_new = parse_time(matches_new[1])
|
|
301
|
+
return [part_1_time_new - part_1_time_old, part_2_time_new - part_2_time_old]
|
|
302
|
+
if len(matches_new) >= 2:
|
|
303
|
+
return [parse_time(matches_new[0]), parse_time(matches_new[1])]
|
|
304
|
+
return [0.0, 0.0]
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def update_readme(readme_path: Path, results_table: str, path: Path) -> None:
|
|
235
308
|
"""Update the README.md with benchmark results."""
|
|
236
309
|
marker_start = "<!-- BENCHMARK_RESULTS_START -->"
|
|
237
310
|
marker_end = "<!-- BENCHMARK_RESULTS_END -->"
|
|
238
|
-
|
|
239
311
|
if not readme_path.exists():
|
|
240
312
|
# Create a new README with results
|
|
241
313
|
content = dedent("""\
|
|
@@ -252,22 +324,73 @@ def update_readme(readme_path: Path, results_table: str) -> None:
|
|
|
252
324
|
marker_end=marker_end,
|
|
253
325
|
results_table=results_table,
|
|
254
326
|
)
|
|
255
|
-
readme_path.write_text(content)
|
|
327
|
+
readme_path.write_text(content, encoding="utf-8")
|
|
256
328
|
console.log(f"Created {readme_path} with benchmark results")
|
|
257
329
|
return
|
|
258
330
|
|
|
259
331
|
content = readme_path.read_text()
|
|
260
|
-
|
|
261
332
|
if marker_start in content and marker_end in content:
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
333
|
+
if path.is_dir():
|
|
334
|
+
# Replace entire existing results table
|
|
335
|
+
pattern = re.compile(re.escape(marker_start) + r".*?" + re.escape(marker_end), re.DOTALL)
|
|
336
|
+
new_section = f"{marker_start}\n{results_table}\n{marker_end}"
|
|
337
|
+
content = pattern.sub(new_section, content)
|
|
338
|
+
else:
|
|
339
|
+
# strip .py from path
|
|
340
|
+
stem = path.stem
|
|
341
|
+
|
|
342
|
+
# substitute the old day row with the new day row
|
|
343
|
+
day_row_pattern = rf"^(\|\s*{stem}\s*\|).*?(\n)"
|
|
344
|
+
old_day_row = get_result_row(content, day_row_pattern)
|
|
345
|
+
if old_day_row is None:
|
|
346
|
+
console.log(f"[red]Could not extract existing row for path {stem} in README[/red]")
|
|
347
|
+
return
|
|
348
|
+
new_day_row = get_result_row(results_table, day_row_pattern)
|
|
349
|
+
if new_day_row is None:
|
|
350
|
+
console.log(f"[red]Could not find new row for path {stem} in results table[/red]")
|
|
351
|
+
return
|
|
352
|
+
content = re.sub(day_row_pattern, new_day_row, content, flags=re.MULTILINE)
|
|
353
|
+
|
|
354
|
+
# substitute the total day row with new time
|
|
355
|
+
totals_pattern = r"^(\|\s*\*\*Total\*\*\s*\|).*?(\n)"
|
|
356
|
+
old_totals = re.search(totals_pattern, content, flags=re.MULTILINE)
|
|
357
|
+
|
|
358
|
+
time_pattern = r"(\d+\.\d+)(ms|s)"
|
|
359
|
+
matches = re.findall(time_pattern, old_totals.group(0)) if old_totals else []
|
|
360
|
+
|
|
361
|
+
if len(matches) < 3:
|
|
362
|
+
console.log("[red]Could not extract existing totals in README[/red]")
|
|
363
|
+
return
|
|
364
|
+
|
|
365
|
+
def parse_to_ms(val_str: str, unit_str: str) -> float:
|
|
366
|
+
val = float(val_str)
|
|
367
|
+
return val * 1000 if unit_str == "s" else val
|
|
368
|
+
|
|
369
|
+
current_p1_ms = parse_to_ms(matches[0][0], matches[0][1])
|
|
370
|
+
current_p2_ms = parse_to_ms(matches[1][0], matches[1][1])
|
|
371
|
+
current_total_ms = parse_to_ms(matches[2][0], matches[2][1])
|
|
372
|
+
|
|
373
|
+
[part_1_diff_ms, part_2_diff_ms] = get_time_diff(old_day_row, new_day_row)
|
|
374
|
+
|
|
375
|
+
new_p1_ms = current_p1_ms + part_1_diff_ms
|
|
376
|
+
new_p2_ms = current_p2_ms + part_2_diff_ms
|
|
377
|
+
new_total_ms = current_total_ms + part_1_diff_ms + part_2_diff_ms
|
|
378
|
+
|
|
379
|
+
p1_seconds = new_p1_ms / 1000.0
|
|
380
|
+
p2_seconds = new_p2_ms / 1000.0
|
|
381
|
+
total_seconds = new_total_ms / 1000.0
|
|
382
|
+
|
|
383
|
+
p1_str = markdown_color(format_time(p1_seconds), time_to_color(p1_seconds))
|
|
384
|
+
p2_str = markdown_color(format_time(p2_seconds), time_to_color(p2_seconds))
|
|
385
|
+
total_str = markdown_color(format_time(total_seconds), time_to_color(total_seconds))
|
|
386
|
+
|
|
387
|
+
new_totals = f"| **Total** | | {p1_str} | {p2_str} | {total_str} |\n"
|
|
388
|
+
content = re.sub(totals_pattern, new_totals, content, flags=re.MULTILINE)
|
|
266
389
|
else:
|
|
267
390
|
# Append results section
|
|
268
391
|
content += f"\n## Benchmark Results\n\n{marker_start}\n{results_table}\n{marker_end}\n"
|
|
269
392
|
|
|
270
|
-
readme_path.write_text(content)
|
|
393
|
+
readme_path.write_text(content, encoding="utf-8")
|
|
271
394
|
console.log(f"Updated {readme_path} with benchmark results")
|
|
272
395
|
|
|
273
396
|
|
|
@@ -289,8 +412,18 @@ def markdown_color(formatted_time: str, color: Color) -> str:
|
|
|
289
412
|
def build_console_table(
|
|
290
413
|
results: list[DayResult], current_running: str | None, total_part_1: float, total_part_2: float, total_time: float
|
|
291
414
|
) -> Table:
|
|
415
|
+
# Check if any result has a variant
|
|
416
|
+
has_variants = any(r.variant for r in results)
|
|
417
|
+
# Also check if current_running has a variant
|
|
418
|
+
if current_running:
|
|
419
|
+
_, current_variant = split_day_name(current_running)
|
|
420
|
+
if current_variant:
|
|
421
|
+
has_variants = True
|
|
422
|
+
|
|
292
423
|
table = Table(title=f"Advent of Code {AOC_YEAR} Benchmark")
|
|
293
424
|
table.add_column("Day", style="cyan", justify="right")
|
|
425
|
+
if has_variants:
|
|
426
|
+
table.add_column("Variant", style="cyan", justify="left")
|
|
294
427
|
table.add_column("Status", justify="center")
|
|
295
428
|
table.add_column("Part 1", justify="right")
|
|
296
429
|
table.add_column("Part 2", justify="right")
|
|
@@ -301,26 +434,100 @@ def build_console_table(
|
|
|
301
434
|
p2_time = console_color(format_time(r.part2_time), time_to_color(r.part2_time))
|
|
302
435
|
total = console_color(format_time(r.total_time), time_to_color(r.total_time))
|
|
303
436
|
status = r.status
|
|
304
|
-
|
|
437
|
+
if not r.in_total and r.total_time > 0:
|
|
438
|
+
if has_variants:
|
|
439
|
+
table.add_row(
|
|
440
|
+
f"[dim strike]{r.day_num}[/dim strike]",
|
|
441
|
+
f"[dim strike]{r.variant}[/dim strike]",
|
|
442
|
+
f"[dim]{status}[/dim]",
|
|
443
|
+
f"[dim]{format_time(r.part1_time)}[/dim]",
|
|
444
|
+
f"[dim]{format_time(r.part2_time)}[/dim]",
|
|
445
|
+
f"[dim]{format_time(r.total_time)}[/dim]",
|
|
446
|
+
)
|
|
447
|
+
else:
|
|
448
|
+
table.add_row(
|
|
449
|
+
f"[dim strike]{r.day_num}[/dim strike]",
|
|
450
|
+
f"[dim]{status}[/dim]",
|
|
451
|
+
f"[dim]{format_time(r.part1_time)}[/dim]",
|
|
452
|
+
f"[dim]{format_time(r.part2_time)}[/dim]",
|
|
453
|
+
f"[dim]{format_time(r.total_time)}[/dim]",
|
|
454
|
+
)
|
|
455
|
+
elif has_variants:
|
|
456
|
+
table.add_row(r.day_num, r.variant, status, p1_time, p2_time, total)
|
|
457
|
+
else:
|
|
458
|
+
table.add_row(r.day_num, status, p1_time, p2_time, total)
|
|
305
459
|
|
|
306
460
|
if current_running is not None:
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
461
|
+
day_num, variant = split_day_name(current_running)
|
|
462
|
+
if has_variants:
|
|
463
|
+
table.add_row(day_num, variant, "⏳", "...", "...", "...")
|
|
464
|
+
else:
|
|
465
|
+
table.add_row(day_num, "⏳", "...", "...", "...")
|
|
466
|
+
|
|
467
|
+
if has_variants:
|
|
468
|
+
table.add_row(
|
|
469
|
+
"Total",
|
|
470
|
+
"",
|
|
471
|
+
"",
|
|
472
|
+
console_color(format_time(total_part_1), time_to_color(total_part_1)),
|
|
473
|
+
console_color(format_time(total_part_2), time_to_color(total_part_2)),
|
|
474
|
+
console_color(format_time(total_time), time_to_color(total_time)),
|
|
475
|
+
)
|
|
476
|
+
else:
|
|
477
|
+
table.add_row(
|
|
478
|
+
"Total",
|
|
479
|
+
"",
|
|
480
|
+
console_color(format_time(total_part_1), time_to_color(total_part_1)),
|
|
481
|
+
console_color(format_time(total_part_2), time_to_color(total_part_2)),
|
|
482
|
+
console_color(format_time(total_time), time_to_color(total_time)),
|
|
483
|
+
)
|
|
316
484
|
return table
|
|
317
485
|
|
|
318
486
|
|
|
319
|
-
def
|
|
320
|
-
|
|
487
|
+
def get_day_number(day_name: str) -> str:
|
|
488
|
+
"""Extract the day number from a filename like '01.py' or '01-alternative.py'."""
|
|
489
|
+
match = re.match(r"(\d\d)", day_name)
|
|
490
|
+
return match.group(1) if match else day_name
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
def select_best_per_day(results: list[DayResult]) -> tuple[list[DayResult], float, float, float]:
|
|
494
|
+
"""Mark the best (fastest) solution for each day as in_total, others as not.
|
|
495
|
+
|
|
496
|
+
Returns updated results and the totals based only on best solutions.
|
|
497
|
+
"""
|
|
498
|
+
day_groups: dict[str, list[DayResult]] = {}
|
|
499
|
+
for r in results:
|
|
500
|
+
day_num = get_day_number(r.day)
|
|
501
|
+
if day_num not in day_groups:
|
|
502
|
+
day_groups[day_num] = []
|
|
503
|
+
day_groups[day_num].append(r)
|
|
321
504
|
|
|
322
|
-
|
|
323
|
-
|
|
505
|
+
total_time = 0.0
|
|
506
|
+
total_part_1 = 0.0
|
|
507
|
+
total_part_2 = 0.0
|
|
508
|
+
|
|
509
|
+
for group in day_groups.values():
|
|
510
|
+
completed = [r for r in group if r.total_time > 0]
|
|
511
|
+
if completed:
|
|
512
|
+
best = min(completed, key=lambda r: r.total_time)
|
|
513
|
+
for r in group:
|
|
514
|
+
r.in_total = r is best
|
|
515
|
+
total_time += best.total_time
|
|
516
|
+
total_part_1 += best.part1_time
|
|
517
|
+
total_part_2 += best.part2_time
|
|
518
|
+
else:
|
|
519
|
+
for r in group:
|
|
520
|
+
r.in_total = False
|
|
521
|
+
|
|
522
|
+
return results, total_time, total_part_1, total_part_2
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
def benchmark(path: Path) -> None:
|
|
526
|
+
console.log("[bold]Running benchmarks for Advent of Code[/bold]\n")
|
|
527
|
+
if path.is_dir():
|
|
528
|
+
day_files = sorted(path.glob("[0-9][0-9]*.py"))
|
|
529
|
+
else:
|
|
530
|
+
day_files = [Path(path)] if path.exists() else []
|
|
324
531
|
if not day_files:
|
|
325
532
|
console.log("[yellow]No day files found[/yellow]")
|
|
326
533
|
return
|
|
@@ -354,9 +561,7 @@ def benchmark(directory: Path) -> None:
|
|
|
354
561
|
result = run_day(filepath)
|
|
355
562
|
results.append(result)
|
|
356
563
|
|
|
357
|
-
total_part_1
|
|
358
|
-
total_part_2 += result.part2_time
|
|
359
|
-
total_time += result.total_time
|
|
564
|
+
_, total_time, total_part_1, total_part_2 = select_best_per_day(results)
|
|
360
565
|
|
|
361
566
|
live.update(
|
|
362
567
|
build_console_table(
|
|
@@ -368,11 +573,14 @@ def benchmark(directory: Path) -> None:
|
|
|
368
573
|
)
|
|
369
574
|
)
|
|
370
575
|
|
|
371
|
-
|
|
576
|
+
if path.is_dir():
|
|
577
|
+
readme_path = path / "README.md"
|
|
578
|
+
else:
|
|
579
|
+
readme_path = path.parent / "README.md"
|
|
372
580
|
results_table = build_markdown_table(
|
|
373
581
|
results, total_time=total_time, total_part_1=total_part_1, total_part_2=total_part_2
|
|
374
582
|
)
|
|
375
|
-
update_readme(readme_path, results_table)
|
|
583
|
+
update_readme(readme_path, results_table, path)
|
|
376
584
|
|
|
377
585
|
|
|
378
586
|
def run(filepath: Path, benchmark: bool = False) -> None: # noqa: FBT001, FBT002
|
|
@@ -469,11 +677,13 @@ def main() -> None:
|
|
|
469
677
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
470
678
|
epilog=dedent("""\
|
|
471
679
|
Examples:
|
|
472
|
-
adventofcode benchmark
|
|
473
|
-
adventofcode benchmark ./2024
|
|
680
|
+
adventofcode benchmark # Run benchmarks in current directory
|
|
681
|
+
adventofcode benchmark ./2024 # Run benchmarks in the ./2024 directory
|
|
682
|
+
adventofcode benchmark 02.py # Run benchmarks for day 2 only
|
|
683
|
+
adventofcode benchmark ./2024/02.py # Run benchmarks in the ./2024 directory for day 2 only
|
|
474
684
|
|
|
475
685
|
The benchmark will:
|
|
476
|
-
1. Find
|
|
686
|
+
1. Find selected day files (01.py, 02.py, etc.)
|
|
477
687
|
2. Run each day script (python 01.py, etc.)
|
|
478
688
|
3. Parse execution times from the output
|
|
479
689
|
4. Display a live-updating table in the console
|
|
@@ -485,11 +695,11 @@ def main() -> None:
|
|
|
485
695
|
"""),
|
|
486
696
|
)
|
|
487
697
|
benchmark_parser.add_argument(
|
|
488
|
-
"
|
|
698
|
+
"path",
|
|
489
699
|
type=Path,
|
|
490
700
|
nargs="?",
|
|
491
701
|
default=Path("."),
|
|
492
|
-
help="
|
|
702
|
+
help="Path where benchmarked file(s) are located (default: current directory)",
|
|
493
703
|
)
|
|
494
704
|
|
|
495
705
|
# Run Command
|
|
@@ -522,7 +732,7 @@ def main() -> None:
|
|
|
522
732
|
case "init":
|
|
523
733
|
init_templates(args.year, args.directory, 12 if args.year >= 2025 else 25)
|
|
524
734
|
case "benchmark":
|
|
525
|
-
benchmark(args.
|
|
735
|
+
benchmark(args.path)
|
|
526
736
|
case "run":
|
|
527
737
|
run(args.filepath, benchmark=args.benchmark)
|
|
528
738
|
case _:
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "25.8"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|