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

Method benchmark_time

Tools/picklebench/memory_dos_impact.py:237–258  ·  view source on GitHub ↗

Measure unpickling time over multiple iterations.

(self)

Source from the content-addressed store, hash-verified

235 self.pickle_size = len(self.pickle_data)
236
237 def benchmark_time(self) -> Dict[str, float]:
238 """Measure unpickling time over multiple iterations."""
239 times = []
240
241 for _ in range(self.iterations):
242 start = perf_counter()
243 result = pickle.loads(self.pickle_data)
244 elapsed = perf_counter() - start
245 times.append(elapsed)
246
247 # Verify correctness (first iteration only)
248 if len(times) == 1:
249 if result != self.obj:
250 raise ValueError("Unpickled object doesn't match original!")
251
252 return {
253 'mean': statistics.mean(times),
254 'median': statistics.median(times),
255 'stdev': statistics.stdev(times) if len(times) > 1 else 0.0,
256 'min': min(times),
257 'max': max(times),
258 }
259
260 def benchmark_memory(self) -> int:
261 """Measure peak memory usage during unpickling."""

Callers 1

run_allMethod · 0.95

Calls 5

meanMethod · 0.80
medianMethod · 0.80
stdevMethod · 0.80
loadsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected