Benchmarks any iterable (e.g `tf.data.Dataset`). Usage: ```py ds = tfds.load('mnist', split='train') ds = ds.batch(32).prefetch(buffer_size=tf.data.AUTOTUNE) tfds.benchmark(ds, batch_size=32) ``` Reports: - Total execution time - Setup time (first warmup batch) - Number of ex
(
ds: Iterable[Any],
*,
num_iter: Optional[int] = None,
batch_size: int = 1,
)
| 238 | |
| 239 | |
| 240 | def benchmark( |
| 241 | ds: Iterable[Any], |
| 242 | *, |
| 243 | num_iter: Optional[int] = None, |
| 244 | batch_size: int = 1, |
| 245 | ) -> BenchmarkResult: |
| 246 | """Benchmarks any iterable (e.g `tf.data.Dataset`). |
| 247 | |
| 248 | Usage: |
| 249 | |
| 250 | ```py |
| 251 | ds = tfds.load('mnist', split='train') |
| 252 | ds = ds.batch(32).prefetch(buffer_size=tf.data.AUTOTUNE) |
| 253 | tfds.benchmark(ds, batch_size=32) |
| 254 | ``` |
| 255 | |
| 256 | Reports: |
| 257 | |
| 258 | - Total execution time |
| 259 | - Setup time (first warmup batch) |
| 260 | - Number of examples/sec |
| 261 | |
| 262 | Args: |
| 263 | ds: Dataset to benchmark. Can be any iterable. Note: The iterable will be |
| 264 | fully consumed. |
| 265 | num_iter: Number of iteration to perform (iteration might be batched) |
| 266 | batch_size: Batch size of the dataset, used to normalize iterations |
| 267 | |
| 268 | Returns: |
| 269 | statistics: The recorded statistics, for eventual post-processing |
| 270 | """ |
| 271 | print('\n************ Summary ************\n') |
| 272 | raw_results = raw_benchmark(ds=ds, num_iter=num_iter, batch_size=batch_size) |
| 273 | return BenchmarkResult( |
| 274 | stats=raw_results.stats_pd(), |
| 275 | raw_stats=raw_results.raw_stats_pd(), |
| 276 | ) |
| 277 | |
| 278 | |
| 279 | def _log_stats(msg: str, start: int, end: int, num_examples: int) -> StatDict: |
nothing calls this directly
no test coverage detected