code: def _run_function_under_strategies(
      user_fn,
      iters,
      config,
      hardware,
      extra_columns,
      use_autograph,
      print_intermediates=False,
  ):
      """Run user_fn with varying backends. See public API for details."""
  
      def run_one(function, runtime):
          """Run user_fn. See public API for details."""
          first_iter_time, total_time = _run_function(function, iters)
          new_dict = _merge_dicts(
              {
                  "runtime": runtime,
                  "hardware": hardware,
                  "iters": iters,
                  "first_iter_time": first_iter_time,
                  "total_time": total_time,
                  "avg_warm_iter_time": (total_time - first_iter_time)
                  / (iters - 1),
              },
              extra_columns,
          )
  
          if print_intermediates:
              print("New benchmark result:")
              pprint.pprint(new_dict)
  
          return new_dict
  
      data_dicts = []
  
      if RUNTIME_EAGER in config.strategies:
          data_dicts.append(run_one(user_fn, RUNTIME_EAGER))
  
      if RUNTIME_FUNCTION in config.strategies:
          graph_fn = tf.function(user_fn, autograph=use_autograph)
          data_dicts.append(run_one(graph_fn, RUNTIME_FUNCTION))
  
      if RUNTIME_XLA in config.strategies:
          xla_fn = tf.function(
              user_fn, autograph=use_autograph, jit_compile=True
          )
          data_dicts.append(run_one(xla_fn, RUNTIME_XLA))
  
      if RUNTIME_XLA_AUTOCLUSTER in config.strategies:
  
          @tf.function(autograph=use_autograph)
          def autocluster_fn(*args, **kwargs):
              with tf.xla.experimental.jit_scope(compile_ops=True):
                  return user_fn(*args, **kwargs)
  
          data_dicts.append(
              run_one(autocluster_fn, RUNTIME_XLA_AUTOCLUSTER)
          )
  
      return data_dicts
  
file_path: probability/tensorflow_probability/python/debugging/benchmarking/benchmark_tf_function.py
imports: import collections
  import pprint
  import time
  import tensorflow.compat.v2
label_desc: Use image node_id 4 for calling a global function with example usage: _run_function_under_strategies(user_fn, iters, config, hardware, extra_columns, use_autograph, print_intermediates) and returns: data_dicts, new_dict, user_fn