Measure unpickling time over multiple iterations.
(self)
| 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.""" |