mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Review comments
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
import time
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
@@ -14,17 +15,19 @@ from . import days
|
|||||||
default="-",
|
default="-",
|
||||||
help="Problem input file",
|
help="Problem input file",
|
||||||
)
|
)
|
||||||
@click.option("-t", "--time", is_flag=True, help="Print elapsed time afterwards")
|
@click.option("-t", "--time", "timing", is_flag=True, help="Print elapsed time afterwards")
|
||||||
@click.argument("day", required=True)
|
@click.argument("day", required=True)
|
||||||
def main(day: int, time: bool, data: str) -> None:
|
def main(day: int, timing: bool, data: str) -> None:
|
||||||
runner_class = days.get_runner(day)
|
runner_class = days.get_runner(day)
|
||||||
|
|
||||||
start = datetime.datetime.now()
|
start = time.perf_counter_ns()
|
||||||
|
|
||||||
part1, part2 = runner_class.run_both(data)
|
part1, part2 = runner_class.run_both(data)
|
||||||
|
|
||||||
if time:
|
if timing:
|
||||||
click.echo(f"Elapsed: {datetime.datetime.now() - start}", err=True)
|
elapsed = time.perf_counter_ns() - start
|
||||||
|
delta = datetime.timedelta(microseconds=elapsed / 1000)
|
||||||
|
click.echo(f"Elapsed: {delta}", err=True)
|
||||||
|
|
||||||
click.echo(part1)
|
click.echo(part1)
|
||||||
click.echo(part2)
|
click.echo(part2)
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import importlib
|
import importlib
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import Any, Tuple, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
|
|
||||||
class Runner(ABC):
|
class Runner(ABC):
|
||||||
@classmethod
|
@classmethod
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def run_both(cls, data: str) -> Tuple[Any, Any]:
|
def run_both(cls, data: str) -> tuple[Any, Any]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -22,7 +22,7 @@ class Runner(ABC):
|
|||||||
|
|
||||||
class SeparateRunner(Runner):
|
class SeparateRunner(Runner):
|
||||||
@classmethod
|
@classmethod
|
||||||
def run_both(cls, data: str) -> Tuple[Any, Any]:
|
def run_both(cls, data: str) -> tuple[Any, Any]:
|
||||||
return (cls.part1(data), cls.part2(data))
|
return (cls.part1(data), cls.part2(data))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user