1# Copyright 2018 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.range()`.""" 16from tensorflow.python.data.benchmarks import benchmark_base 17from tensorflow.python.data.ops import dataset_ops 18from tensorflow.python.data.ops import options as options_lib 19 20 21class RangeBenchmark(benchmark_base.DatasetBenchmarkBase): 22 """Benchmarks for `tf.data.Dataset.range()`.""" 23 24 def _benchmark_range(self, num_elements, autotune, benchmark_id): 25 options = options_lib.Options() 26 options.autotune.enabled = autotune 27 dataset = dataset_ops.Dataset.range(num_elements) 28 dataset = dataset.with_options(options) 29 30 self.run_and_report_benchmark( 31 dataset, 32 num_elements=num_elements, 33 extras={ 34 "model_name": "range.benchmark.%d" % benchmark_id, 35 "parameters": "%d.%s" % (num_elements, autotune), 36 }, 37 name="modeling_%s" % ("on" if autotune else "off")) 38 39 def benchmark_range_with_modeling(self): 40 self._benchmark_range(num_elements=10000000, autotune=True, benchmark_id=1) 41 42 def benchmark_range_without_modeling(self): 43 self._benchmark_range(num_elements=50000000, autotune=False, benchmark_id=2) 44 45 46if __name__ == "__main__": 47 benchmark_base.test.main() 48