Skip to content

Commit

Permalink
perf: add Quantitiy.__init__() checks for presence of argument
Browse files Browse the repository at this point in the history
  • Loading branch information
unexcellent committed Dec 11, 2024
1 parent b743762 commit 2c38b8c
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 159 deletions.
2 changes: 1 addition & 1 deletion benchmarking/bench_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def init_only_base_unit():
Time(seconds=1)
Time(seconds=1, milliseconds=1)


def bench_init(benchmark):
Expand Down
5 changes: 3 additions & 2 deletions generate/generate_boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ def _generate_init(units: dict[str, str]) -> list[str]:
]

for unit in units:
code.append(_indent(f"{unit}: float = 0.0,", 2))
code.append(_indent(f"{unit}: float | None = None,", 2))

code.append(_indent(") -> None:", 1))
code.append(_indent("self._base_value = _base_value", 2))

for unit, factor in units.items():
code.append(_indent(f"self._base_value += {unit} * {factor}", 2))
code.append(_indent(f"if {unit} is not None:", 2))
code.append(_indent(f"self._base_value += {unit} * {factor}", 3))

code.append("")
return code
Expand Down
Loading

0 comments on commit 2c38b8c

Please sign in to comment.