code: def test_grappler_optimization(self):
      @polymorphic_function.function
      def brancher(inp):
          x = constant_op.constant(1)
          for _ in range(1000):
              if inp:
                  x = x + constant_op.constant(1)
              else:
                  x = x + constant_op.constant(2)
          return x
  
      @polymorphic_function.function
      def brancher_true():
          left = constant_op.constant(True)
          x = constant_op.constant(1)
          for _ in range(1000):
              if left:
                  x = x + constant_op.constant(1)
              else:
                  x = x + constant_op.constant(2)
          return x
  
      x = constant_op.constant(True)
      self.assertEqual(
          brancher(x), brancher_true()
      )  # Trace each function once.
  
      benchmark = min(
          timeit.repeat(lambda: brancher(x), repeat=5, number=100)
      )
      opt_benchmark = min(
          timeit.repeat(brancher_true, repeat=5, number=100)
      )
  
      # Constant folded execution is usually 15 - 20 times faster. Here we check
      # for a 3x speedup to account for various machines the test might run on.
      self.assertLess(opt_benchmark * 3, benchmark)
  
file_path: tensorflow/tensorflow/python/eager/small_constants_optimizer_test.py
imports: import contextlib
  import timeit
  from tensorflow.python.eager import context
  from tensorflow.python.eager.polymorphic_function import polymorphic_function
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.platform import test
label_desc: Use image node_id 1 for calling the FunctionTest obj's underlying member method code with example usage: obj.test_grappler_optimization() and returns: x, x