code: def speed_metrics(
      split, start_time, num_samples=None, num_steps=None
  ):
      """
      Measure and return speed performance metrics.
  
      This function requires a time snapshot `start_time` before the operation to be measured starts and this function
      should be run immediately after the operation to be measured has completed.
  
      Args:
      - split: name to prefix metric (like train, eval, test...)
      - start_time: operation start time
      - num_samples: number of samples processed
      """
      runtime = time.time() - start_time
      result = {f"{split}_runtime": round(runtime, 4)}
      if num_samples is not None:
          samples_per_second = num_samples / runtime
          result[f"{split}_samples_per_second"] = round(
              samples_per_second, 3
          )
      if num_steps is not None:
          steps_per_second = num_steps / runtime
          result[f"{split}_steps_per_second"] = round(
              steps_per_second, 3
          )
      return result
  
imports: import copy
  import functools
  import gc
  import inspect
  import os
  import random
  import re
  import threading
  import time
  from typing import Any, Dict, List, NamedTuple, Optional, Tuple, Union
  import numpy
  from .utils import ExplicitEnum, is_psutil_available, is_tf_available, is_torch_available, is_torch_cuda_available, is_torch_tpu_available, requires_backends
label_desc: Use image node_id 12 for calling a global function with example usage: speed_metrics(split, start_time, num_samples, num_steps) and returns: result