|
17 | 17 |
|
18 | 18 |
|
19 | 19 | import numpy as np |
20 | | -from packaging import version |
21 | | -import pyperf |
22 | | -import rich.progress |
23 | 20 |
|
24 | 21 |
|
25 | 22 | from . import bases as mbases |
|
30 | 27 | from . import plot |
31 | 28 | from . import runners |
32 | 29 | from . import util |
33 | | -from .util import PathLike |
| 30 | +from .util import PathLike, rich_track |
34 | 31 |
|
35 | 32 |
|
36 | 33 | CombinedData = list[tuple[str, np.ndarray | None, float]] |
@@ -190,14 +187,18 @@ def write_table(self, filename: PathLike) -> str | None: |
190 | 187 | def _get_combined_data( |
191 | 188 | self, ref_data: dict[str, np.ndarray], head_data: dict[str, np.ndarray] |
192 | 189 | ) -> CombinedData: |
| 190 | + import pyperf |
| 191 | + |
193 | 192 | def remove_outliers(values, m=2): |
194 | 193 | return values[ |
195 | 194 | abs(values - np.mean(values)) < np.multiply(m, np.std(values)) |
196 | 195 | ] |
197 | 196 |
|
198 | 197 | def calculate_diffs(ref_values, head_values) -> tuple[np.ndarray | None, float]: |
199 | 198 | if len(ref_values) > 3 and len(head_values) > 3: |
200 | | - sig, t_score = pyperf._utils.is_significant(ref_values, head_values) |
| 199 | + sig, t_score = pyperf._utils.is_significant( # pyright: ignore |
| 200 | + ref_values, head_values |
| 201 | + ) |
201 | 202 | if not sig: |
202 | 203 | return None, 0.0 |
203 | 204 | else: |
@@ -461,6 +462,7 @@ def __init__( |
461 | 462 | self._commit_datetime = commit_datetime |
462 | 463 | self._filename = None |
463 | 464 | self.bases = {} |
| 465 | + self._contents: None | dict[str, Any] = None |
464 | 466 |
|
465 | 467 | @classmethod |
466 | 468 | def from_filename(cls, filename: PathLike) -> "Result": |
@@ -496,6 +498,22 @@ def from_filename(cls, filename: PathLike) -> "Result": |
496 | 498 | obj._filename = filename |
497 | 499 | return obj |
498 | 500 |
|
| 501 | + @classmethod |
| 502 | + def from_online_json(cls, url: str, json_content: str | dict) -> "Result": |
| 503 | + from urllib.parse import urlparse |
| 504 | + |
| 505 | + parsed_url = urlparse(url) |
| 506 | + path = "/".join(parsed_url.path.split("/")[-2:]) |
| 507 | + |
| 508 | + result = cls.from_filename(Path(unquote(path))) |
| 509 | + result._filename = None |
| 510 | + if isinstance(json_content, str): |
| 511 | + result._contents = json.loads(json_content) |
| 512 | + else: |
| 513 | + result._contents = json_content |
| 514 | + |
| 515 | + return result |
| 516 | + |
499 | 517 | @classmethod |
500 | 518 | def from_arbitrary_filename(cls, filename: PathLike) -> "Result": |
501 | 519 | filename = Path(filename) |
@@ -600,10 +618,14 @@ def result_info(self) -> tuple[str | None, str | None, str | None]: |
600 | 618 | f"Unknown result type (extra={self.extra} suffix={self.suffix})" |
601 | 619 | ) |
602 | 620 |
|
603 | | - @functools.cached_property |
| 621 | + @property |
604 | 622 | def contents(self) -> dict[str, Any]: |
| 623 | + if self._contents is not None: |
| 624 | + return self._contents |
605 | 625 | with self.filename.open("rb") as fd: |
606 | | - return json.load(fd) |
| 626 | + self._contents = json.load(fd) |
| 627 | + assert self._contents is not None |
| 628 | + return self._contents |
607 | 629 |
|
608 | 630 | @property |
609 | 631 | def metadata(self) -> dict[str, Any]: |
@@ -705,6 +727,8 @@ def get_timing_data(self) -> dict[str, np.ndarray]: |
705 | 727 | return data |
706 | 728 |
|
707 | 729 | def get_memory_data(self) -> dict[str, np.ndarray]: |
| 730 | + from packaging import version |
| 731 | + |
708 | 732 | data = {} |
709 | 733 | excluded = util.get_excluded_benchmarks() |
710 | 734 |
|
@@ -800,7 +824,7 @@ def find_match(result, candidates, base, func): |
800 | 824 | bases = [] |
801 | 825 |
|
802 | 826 | if progress: |
803 | | - track = rich.progress.track # type: ignore |
| 827 | + track = rich_track # type: ignore |
804 | 828 | else: |
805 | 829 |
|
806 | 830 | def track(it, *_args, **_kwargs): |
|
0 commit comments