code: def iter_benchmark(
      iterator,
      num_iter: int,
      warmup: int = 5,
      max_time_seconds: float = 60,
  ) -> Tuple[float, List[float]]:
      """
      Benchmark an iterator/iterable for `num_iter` iterations with an extra
      `warmup` iterations of warmup.
      End early if `max_time_seconds` time is spent on iterations.
  
      Returns:
          float: average time (seconds) per iteration
          list[float]: time spent on each iteration. Sometimes useful for further analysis.
      """
      num_iter, warmup = int(num_iter), int(warmup)
  
      iterator = iter(iterator)
      for _ in range(warmup):
          next(iterator)
      timer = Timer()
      all_times = []
      for curr_iter in tqdm.trange(num_iter):
          start = timer.seconds()
          if start > max_time_seconds:
              num_iter = curr_iter
              break
          next(iterator)
          all_times.append(timer.seconds() - start)
      avg = timer.seconds() / num_iter
      return avg, all_times
  
imports: import logging
  import numpy
  from itertools import count
  from typing import List, Tuple
  import torch
  import tqdm
  from fvcore.common.timer import Timer
  from detectron2.utils import comm
  from .build import build_batch_data_loader
  from .common import DatasetFromList, MapDataset
  from .samplers import TrainingSampler
label_desc: Use image node_id 1 for calling a global function with example usage: iter_benchmark(iterator, num_iter, warmup, max_time_seconds) and returns: avg,  all_times