py2http.sizeof¶
Approximate the memory an object holds, without walking more of it than a budget.
bounded_deep_sizeof is how py2http bounds the objects clients create or grow
through class and instance endpoints (py2http.obj_dispatch).
Functions
|
Approximate memory held by |
- py2http.sizeof.bounded_deep_sizeof(obj, limit=None)[source]¶
Approximate memory held by
objand everything it references (containers, instance__dict__and__slots__, what a bound method, apartialor a function’s closure, attributes and defaults hold), counting each object once. Stops as soon as the total exceedslimit, so measuring costs at most aboutlimitbytes’ worth of objects. Classes, modules and the code of functions are shared, so not counted, and neither is what classes and modules hold (class attributes, module globals), nor caches kept in C (lru_cache). Holding a bound method of another object counts that whole object, as holding the object itself would.>>> small, big = bounded_deep_sizeof([1, 2]), bounded_deep_sizeof(list(range(1000))) >>> small < big True >>> bounded_deep_sizeof(list(range(10**6)), limit=1000) > 1000 True- Return type: