code: def _log_stats(
      msg: str, start: int, end: int, num_examples: int
  ) -> StatDict:
      """Log and returns stats."""
      if not num_examples:
          stats = {
              "duration": 0.0,
              "num_examples": 0,
              "avg": 0.0,
          }
      else:
          # Make sure the total time is not 0.
          total_time_ns = (end - start) or 1
          total_time_s = _ns_to_s(total_time_ns)
          stats = {
              "duration": total_time_s,
              "num_examples": num_examples,
              "avg": num_examples / total_time_s,
          }
      print(
          "Examples/sec ({}) {avg:.2f} ex/sec (total: {num_examples} ex, "
          "{duration:.2f} sec)".format(msg, **stats)
      )
      return stats
  
imports: from __future__ import annotations
  import dataclasses
  import statistics
  import textwrap
  import time
  from typing import Any, Dict, Iterable, List, Optional, Union
  from absl import logging
  from tensorflow_datasets.core.utils import tqdm_utils
  from tensorflow_datasets.core.utils.lazy_imports_utils import pandas
label_desc: Use image node_id 4 for calling a global function with example usage: _log_stats(msg, start, end, num_examples) and returns: stats