Download tasks/swe-next-1a113b4bab7fa544fc2b/tests/source/benchmarks/version.py from FineEnvs/repo2rlenv-swe-next: direct link, hf CLI and curl.
- Browser
- Download file 2.09 kB
-
https://huggingface.co/datasets/FineEnvs/repo2rlenv-swe-next/resolve/main/tasks/swe-next-1a113b4bab7fa544fc2b/tests/source/benchmarks/version.py
- Command line
-
hf download hf://datasets/FineEnvs/repo2rlenv-swe-next/tasks/swe-next-1a113b4bab7fa544fc2b/tests/source/benchmarks/version.py
-
curl -L -o version.py https://huggingface.co/datasets/FineEnvs/repo2rlenv-swe-next/resolve/main/tasks/swe-next-1a113b4bab7fa544fc2b/tests/source/benchmarks/version.py
2.09 kB
| from __future__ import annotations | |
| from pathlib import Path | |
| from packaging.version import InvalidVersion, Version | |
| from . import add_attributes | |
| DIR = Path(__file__).parent.resolve() | |
| def valid_version(v: str) -> Version | None: | |
| try: | |
| return Version(v) | |
| except InvalidVersion: | |
| return None | |
| class TimeVersionSuite: | |
| rounds = 4 | |
| def setup(self) -> None: | |
| with (DIR / "version_sample.txt").open() as f: | |
| self.versions = [v.strip() for v in f.readlines()] | |
| self.valid_versions = [v for v in self.versions if valid_version(v)] | |
| self.version_objects_cold = [Version(v) for v in self.valid_versions] | |
| self.version_objects_warm = [Version(v) for v in self.valid_versions] | |
| for v in self.version_objects_warm: | |
| _ = v._key | |
| def time_constructor(self) -> None: | |
| for v in self.versions: | |
| try: | |
| Version(v) | |
| except InvalidVersion: # noqa: PERF203 | |
| pass | |
| def time_hash(self) -> None: | |
| for v in self.valid_versions: | |
| hash(Version(v)) | |
| def time_hash_warm(self) -> None: | |
| for v in self.version_objects_warm: | |
| hash(v) | |
| def time_str(self) -> None: | |
| for version in self.valid_versions: | |
| str(Version(version)) | |
| def time_sort_cold(self) -> None: | |
| """Sorting when _key needs to be calculated during comparison.""" | |
| for v in self.version_objects_cold: | |
| v._key_cache = None | |
| if hasattr(v, "_hash_cache"): | |
| v._hash_cache = None | |
| sorted(self.version_objects_cold) | |
| def time_sort_warm(self) -> None: | |
| """Sorting when _key is already cached.""" | |
| sorted(self.version_objects_warm) | |