Skip to content

Commit

Permalink
BLD: Ensure pympler is present
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoZeke committed Feb 25, 2023
1 parent b63a970 commit bbd8f8a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions asv/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,20 +706,25 @@ def __init__(self, name, func, attr_sources):

def run(self, *param):
if ON_PYPY:
raise UserWarning("asizeof doesn't work on pypy")
raise NotImplementedError("asizeof doesn't work on pypy")
return

try:
from pympler.asizeof import asizeof
except ImportError:
raise UserWarning("pympler not found, memory benchmarks shall fail")
try:
subprocess.check_output(["python", "-mpip", "install", "pympler==0.9"])
except subprocess.CalledProcessError as e:
raise NotImplementedError(f"Failed to install pympler: {e.output.decode()}")
raise NotImplementedError("pympler not found, installed successfully")

obj = self.func(*param)

sizeof2 = asizeof([obj, obj])
sizeofcopy = asizeof([obj, copy.copy(obj)])

return sizeofcopy - sizeof2


class PeakMemBenchmark(Benchmark):
"""
Represents a single benchmark for tracking the peak memory consumption
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ test = [
"selenium",
"pytest-rerunfailures",
"python-hglib",
"pympler; platform_python_implementation != \"PyPy\"",
]
doc = [
"sphinx",
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ python-hglib
flake8
isort>= 5.11.5
json5
pympler; platform_python_implementation != "PyPy"

0 comments on commit bbd8f8a

Please sign in to comment.