• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Benchmarks for `tf.data.Dataset.prefetch()`."""
16from tensorflow.python.data.benchmarks import benchmark_base
17from tensorflow.python.data.ops import dataset_ops
18
19
20class PrefetchBenchmark(benchmark_base.DatasetBenchmarkBase):
21  """Benchmarks for `tf.data.Dataset.prefetch()`."""
22
23  def benchmark_prefetch(self):
24    num_elements = 1000000
25    for prefetch_buffer in [1, 5, 10, 20, 100]:
26      dataset = dataset_ops.Dataset.range(num_elements)
27      dataset = dataset.prefetch(prefetch_buffer)
28
29      self.run_and_report_benchmark(
30          dataset,
31          num_elements=num_elements,
32          extras={
33              "model_name": "prefetch.benchmark.1",
34              "parameters": "%d" % prefetch_buffer,
35          },
36          name="prefetch_{}".format(prefetch_buffer))
37
38
39if __name__ == "__main__":
40  benchmark_base.test.main()
41