|
| 1 | +# Copyright 2022 Google LLC |
| 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 | +# pylint: disable=line-too-long |
| 15 | +r"""Benchmarks for struct2tensor. |
| 16 | +
|
| 17 | +
|
| 18 | +Usage: |
| 19 | +blaze run -c opt --dynamic_mode=off \ |
| 20 | + --run_under='perflab \ |
| 21 | + --constraints=arch=x86_64,platform_family=iota,platform_genus=sandybridge' \ |
| 22 | + //struct2tensor/benchmarks:ops_benchmark \ |
| 23 | + -- --notest_mode |
| 24 | +
|
| 25 | +Results: |
| 26 | +Num Iterations|Total (wall) Time (s)|Wall Time avg(ms)|Wall Time std|User CPU avg (ms)|User CPU std|System CPU avg (ms)|System CPU std |
| 27 | +equi_join_any_indices_monotonic_increasing_1000: 10000|12.046009018551558|1.2046009018551558|0.9495328669791991|1.2590000000000146|6.046119048963948|0.09000000000014552|5.595813730989087 |
| 28 | +equi_join_any_indices_random_1000: 10000|12.026614569593221|1.2026614569593221|0.7186884686309326|1.2809999999997672|17.961518911690458|0.10100000000093132|10.87068154147507 |
| 29 | +equi_join_indices_monotonic_increasing_1000: 10000|12.022087568882853|1.2022087568882853|0.6371426815230887|1.256000000000131|9.673456340434292|0.10300000000061119|13.443108707001388 |
| 30 | +equi_join_indices_random_1000: 10000|12.04043987870682|1.2040439878706821|0.6657185129990686|1.2420000000001892|7.272474742950086|0.08600000000005821|5.508487482377499 |
| 31 | +""" |
| 32 | +# pylint: disable=line-too-long |
| 33 | + |
| 34 | +from absl.testing import parameterized |
| 35 | +from struct2tensor.benchmarks import struct2tensor_benchmark_util |
| 36 | +from struct2tensor.ops import struct2tensor_ops |
| 37 | +import tensorflow as tf |
| 38 | + |
| 39 | + |
| 40 | +class EquiJoinIndicesBenchmarks(struct2tensor_benchmark_util.OpsBenchmarks): |
| 41 | + """Benchmarks for EquiJoinIndices.""" |
| 42 | + |
| 43 | + @parameterized.named_parameters(*[ |
| 44 | + dict( |
| 45 | + testcase_name="equi_join_indices_monotonic_increasing", |
| 46 | + fn_name="equi_join_indices_monotonic_increasing", |
| 47 | + fn_args=[], |
| 48 | + data_key="monotonic_increasing", |
| 49 | + ), |
| 50 | + dict( |
| 51 | + testcase_name="equi_join_indices_random", |
| 52 | + fn_name="equi_join_indices_random", |
| 53 | + fn_args=[], |
| 54 | + data_key="random", |
| 55 | + ), |
| 56 | + ]) |
| 57 | + def test_equi_join_indices(self, fn_name, fn_args, data_key): |
| 58 | + |
| 59 | + def benchmark_fn(session): |
| 60 | + a = tf.compat.v1.placeholder(dtype=tf.int64, shape=(None,)) |
| 61 | + b = tf.compat.v1.placeholder(dtype=tf.int64, shape=(None,)) |
| 62 | + result = struct2tensor_ops.equi_join_indices(a, b) |
| 63 | + with tf.control_dependencies(result): |
| 64 | + x = tf.constant(1) |
| 65 | + return session.make_callable(x, feed_list=[a, b]) |
| 66 | + |
| 67 | + self.run_benchmarks(fn_name, benchmark_fn, fn_args, data_key) |
| 68 | + |
| 69 | + |
| 70 | +class EquiJoinAnyIndicesBenchmarks(struct2tensor_benchmark_util.OpsBenchmarks): |
| 71 | + """Benchmarks for EquiJoinAnyIndices.""" |
| 72 | + |
| 73 | + @parameterized.named_parameters(*[ |
| 74 | + dict( |
| 75 | + testcase_name="equi_join_any_indices_monotonic_increasing", |
| 76 | + fn_name="equi_join_any_indices_monotonic_increasing", |
| 77 | + fn_args=[], |
| 78 | + data_key="monotonic_increasing", |
| 79 | + ), |
| 80 | + dict( |
| 81 | + testcase_name="equi_join_any_indices_random", |
| 82 | + fn_name="equi_join_any_indices_random", |
| 83 | + fn_args=[], |
| 84 | + data_key="random", |
| 85 | + ), |
| 86 | + ]) |
| 87 | + def test_equi_join_indices(self, fn_name, fn_args, data_key): |
| 88 | + |
| 89 | + def benchmark_fn(session): |
| 90 | + a = tf.compat.v1.placeholder(dtype=tf.int64, shape=(None,)) |
| 91 | + b = tf.compat.v1.placeholder(dtype=tf.int64, shape=(None,)) |
| 92 | + result = struct2tensor_ops.equi_join_any_indices(a, b) |
| 93 | + with tf.control_dependencies(result): |
| 94 | + x = tf.constant(1) |
| 95 | + return session.make_callable(x, feed_list=[a, b]) |
| 96 | + |
| 97 | + self.run_benchmarks(fn_name, benchmark_fn, fn_args, data_key) |
| 98 | + |
| 99 | + |
| 100 | +if __name__ == "__main__": |
| 101 | + tf.test.main() |
0 commit comments