class_docstr: Benchmarks for MapDefunOp.
docstr: Benchmarks to compare the performance of MapDefun vs tf.map_fn.
code: def benchmark_defun_vs_map_fn(self):
      """Benchmarks to compare the performance of MapDefun vs tf.map_fn."""
  
      @def_function.function(
          input_signature=[tensor_spec.TensorSpec([], dtypes.int32)]
      )
      def defun(x):
          return array_ops.identity(x)
  
      def fn(x):
          return array_ops.identity(x)
  
      base = math_ops.range(10000)
      for input_size in [10, 100, 1000, 10000]:
          num_iters = 10000 // input_size
          map_defun_op = map_defun.map_defun(
              defun, [base], [dtypes.int32], [()]
          )
          map_fn_op = map_fn.map_fn(fn, base)
  
          self._run(
              op=map_defun_op,
              name="with_defun_size_%d" % input_size,
              num_iters=num_iters,
              benchmark_id=1,
          )
          self._run(
              op=map_fn_op,
              name="without_defun_size_%d" % input_size,
              num_iters=num_iters,
              benchmark_id=2,
          )
  
file_path: tensorflow/tensorflow/python/data/experimental/benchmarks/map_defun_benchmark.py
imports: from tensorflow.python.data.benchmarks import benchmark_base
  from tensorflow.python.data.experimental.ops import map_defun
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import tensor_spec
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import map_fn
  from tensorflow.python.ops import math_ops
label_desc: Use image node_id 2 for calling the MapDefunBenchmark obj's underlying member method code with example usage: obj.benchmark_defun_vs_map_fn() and returns: array_ops, array_ops