code: def main():
      tasks = [
          ("add", "add", "torch.add(x, y)"),
          ("add", "add (extra +0)", "torch.add(x, y + zero)"),
      ]
  
      serialized_results = []
      repeats = 2
      timers = [
          benchmark_utils.Timer(
              stmt=stmt,
              globals={
                  "torch": torch
                  if branch == "master"
                  else FauxTorch(torch, overhead_ns),
                  "x": torch.ones((size, 4)),
                  "y": torch.ones((1, 4)),
                  "zero": torch.zeros(()),
              },
              label=label,
              sub_label=sub_label,
              description=f"size: {size}",
              env=branch,
              num_threads=num_threads,
          )
          for branch, overhead_ns in [
              ("master", None),
              ("my_branch", 1),
              ("severe_regression", 5),
          ]
          for label, sub_label, stmt in tasks
          for size in [1, 10, 100, 1000, 10000, 50000]
          for num_threads in [1, 4]
      ]
  
      for i, timer in enumerate(timers * repeats):
          serialized_results.append(
              pickle.dumps(timer.blocked_autorange(min_run_time=0.05))
          )
          print(f"\r{i + 1} / {len(timers) * repeats}", end="")
          sys.stdout.flush()
      print()
  
      comparison = benchmark_utils.Compare(
          [pickle.loads(i) for i in serialized_results]
      )
  
      print("== Unformatted " + "=" * 80 + "\n" + "/" * 95 + "\n")
      comparison.print()
  
      print("== Formatted " + "=" * 80 + "\n" + "/" * 93 + "\n")
      comparison.trim_significant_figures()
      comparison.colorize()
      comparison.print()
  
file_path: pytorch/torch/utils/benchmark/examples/compare.py
imports: import pickle
  import sys
  import time
  import torch
  import torch.utils.benchmark
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types