class_docstr: Benchmarks for `tf.data.experimental.map_and_batch()`.
docstr: Runs benchmark the given series.
docstr_tok: ["Runs","benchmark","the","given","series","."]
code: def _benchmark_series(self, label, series, benchmark_id):
      """Runs benchmark the given series."""
  
      # Decides a proper number of iterations according to the inputs.
      def compute_num_iters(
          map_num_calls, inter_op, element_size, batch_size
      ):
          return 1024 // (
              (element_size * batch_size)
              // min(
                  12
                  if map_num_calls == dataset_ops.AUTOTUNE
                  else map_num_calls,
                  inter_op,
              )
          )
  
      # Makes the dataset based on the inputs.
      def make_dataset(
          map_num_calls,
          element_size,
          batch_size,
          batch_num_calls,
          apply_fusion,
      ):
          k = 1024 * 1024
          x = constant_op.constant(np.random.rand(element_size, 4 * k))
          y = constant_op.constant(np.random.rand(4 * k, 1))
          dataset = dataset_ops.Dataset.range(1000000000000).map(
              lambda _: (x, y)
          )
          dataset = dataset.map(
              math_ops.matmul, num_parallel_calls=map_num_calls
          )
          dataset = dataset.batch(
              batch_size=batch_size, num_parallel_calls=batch_num_calls
          )
          options = options_lib.Options()
          options.experimental_optimization.apply_default_optimizations = (
              False
          )
          options.experimental_optimization.map_and_batch_fusion = (
              apply_fusion
          )
          dataset = dataset.with_options(options)
          return dataset
  
      # Makes the name of the dataset based on the inputs.
      def make_name(
          label,
          map_num_calls,
          inter_op,
          element_size,
          batch_size,
          batch_num_calls,
          apply_fusion,
      ):
          map_num_calls_str = (
              "autotuned"
              if map_num_calls == dataset_ops.AUTOTUNE
              else str(map_num_calls)
          )
          batch_num_calls_str = (
              "autotuned"
              if batch_num_calls == dataset_ops.AUTOTUNE
              else str(
                  1 if batch_num_calls is None else batch_num_calls
              )
          )
          name_str = (
              "%s_id_%s_map_num_calls_%s_batch_num_calls_%s_inter_op_%d"
              "_elem_size_%d_batch_size_%d"
          )
          name = name_str % (
              "fused" if apply_fusion else "chained",
              hashlib.sha1((label).encode("utf-8")).hexdigest()[:8],
              map_num_calls_str,
              batch_num_calls_str,
              inter_op,
              element_size,
              batch_size,
          )
          return name
  
      for (
          map_num_calls,
          inter_op,
          element_size,
          batch_size,
          batch_num_calls,
          apply_fusion,
      ) in series:
          num_iters = compute_num_iters(
              map_num_calls, inter_op, element_size, batch_size
          )
          dataset = make_dataset(
              map_num_calls,
              element_size,
              batch_size,
              batch_num_calls,
              apply_fusion,
          )
          name = make_name(
              label,
              map_num_calls,
              inter_op,
              element_size,
              batch_size,
              batch_num_calls,
              apply_fusion,
          )
  
          session_config = config_pb2.ConfigProto(
              inter_op_parallelism_threads=inter_op,
              use_per_session_threads=True,
          )
  
          self.run_and_report_benchmark(
              dataset=dataset,
              iters=num_iters,
              num_elements=batch_size,
              warmup=True,
              extras={
                  "model_name": "map_and_batch.benchmark.%d"
                  % benchmark_id,
                  "parameters": "%d.%d.%d.%d.%d.%s"
                  % (
                      map_num_calls,
                      inter_op,
                      element_size,
                      batch_size,
                      batch_num_calls,
                      apply_fusion,
                  ),
              },
              session_config=session_config,
              name=name,
          )
  
file_path: tensorflow/tensorflow/python/data/experimental/benchmarks/map_and_batch_benchmark.py
imports: import hashlib
  import itertools
  import numpy
  from tensorflow.core.protobuf import config_pb2
  from tensorflow.python.data.benchmarks import benchmark_base
  from tensorflow.python.data.experimental.ops import batching
  from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.data.ops import options
  from tensorflow.python.framework import constant_op
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import random_ops
label_desc: Use image node_id 2 for calling the MapAndBatchBenchmark obj's underlying member method code with example usage: obj._benchmark_series(label, series, benchmark_id) and returns: unknown, dataset, name