MCPcopy Index your code
hub / github.com/python/cpython / benchmark_memory

Method benchmark_memory

Tools/picklebench/memory_dos_impact.py:260–279  ·  view source on GitHub ↗

Measure peak memory usage during unpickling.

(self)

Source from the content-addressed store, hash-verified

258 }
259
260 def benchmark_memory(self) -> int:
261 """Measure peak memory usage during unpickling."""
262 tracemalloc.start()
263
264 # Warmup
265 pickle.loads(self.pickle_data)
266
267 # Actual measurement
268 gc.collect()
269 tracemalloc.reset_peak()
270 result = pickle.loads(self.pickle_data)
271 current, peak = tracemalloc.get_traced_memory()
272
273 tracemalloc.stop()
274
275 # Verify correctness
276 if result != self.obj:
277 raise ValueError("Unpickled object doesn't match original!")
278
279 return peak
280
281 def run_all(self) -> Dict[str, Any]:
282 """Run all benchmarks and return comprehensive results."""

Callers 1

run_allMethod · 0.95

Calls 5

get_traced_memoryMethod · 0.80
startMethod · 0.45
loadsMethod · 0.45
collectMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected