parameters: (self)
docstring: Benchmarks to compare the performance of MapDefun vs tf.map_fn.
docstring_summary: Benchmarks to compare the performance of MapDefun vs tf.map_fn.
docstring_tokens: Benchmarks to compare the performance of MapDefun vs tf . map_fn .
function: def benchmark_defun_vs_map_fn(self):
      """Benchmarks to compare the performance of MapDefun vs tf.map_fn."""
  
      @function.defun(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(100)
      for input_size in [10, 100, 1000, 10000]:
        num_iters = 100000 // input_size
        map_defun_op = map_defun.map_defun(defun, [base], [dtypes.int32], [()])
        map_fn_op = map_fn.map_fn(fn, base)
  
        self._run(
            map_defun_op, "with_defun_size_%d" % input_size, num_iters=num_iters)
        self._run(
            map_fn_op, "without_defun_size_%d" % input_size, num_iters=num_iters)
function_tokens: def benchmark_defun_vs_map_fn ( self ) : @ function . defun ( 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 ( 100 ) for input_size in [ 10 , 100 , 1000 , 10000 ] : num_iters = 100000 // input_size map_defun_op = map_defun . map_defun ( defun , [ base ] , [ dtypes . int32 ] , [ ( ) ] ) map_fn_op = map_fn . map_fn ( fn , base ) self . _run ( map_defun_op , "with_defun_size_%d" % input_size , num_iters = num_iters ) self . _run ( map_fn_op , "without_defun_size_%d" % input_size , num_iters = num_iters )