Add benchmark for unicode_script op.
PiperOrigin-RevId: 243111734
This commit is contained in:
parent
826a2450d1
commit
1b206c1a31
@ -18,10 +18,12 @@ from __future__ import absolute_import
|
|||||||
from __future__ import division
|
from __future__ import division
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from tensorflow.python.client import session
|
||||||
from tensorflow.python.framework import constant_op
|
from tensorflow.python.framework import constant_op
|
||||||
from tensorflow.python.framework import dtypes
|
from tensorflow.python.framework import dtypes
|
||||||
from tensorflow.python.framework import test_util
|
from tensorflow.python.framework import test_util
|
||||||
from tensorflow.python.ops import string_ops
|
from tensorflow.python.ops import string_ops
|
||||||
|
from tensorflow.python.platform import benchmark
|
||||||
from tensorflow.python.platform import test
|
from tensorflow.python.platform import test
|
||||||
|
|
||||||
|
|
||||||
@ -56,5 +58,31 @@ class UnicodeScriptOpTest(test.TestCase):
|
|||||||
self.assertAllEqual(outputs, [-1, -1])
|
self.assertAllEqual(outputs, [-1, -1])
|
||||||
|
|
||||||
|
|
||||||
|
class UnicodeScriptBenchmarks(test.Benchmark):
|
||||||
|
|
||||||
|
# Generate some random-ish input by jumping around in unicode characters
|
||||||
|
def _generateBenchmarkInput(self, size):
|
||||||
|
chars = []
|
||||||
|
i = 0
|
||||||
|
offset = 0
|
||||||
|
continuity_size = 20
|
||||||
|
while i < size:
|
||||||
|
chars.append(ord("a") + offset)
|
||||||
|
i += 1
|
||||||
|
offset += 1
|
||||||
|
if i % continuity_size == 0:
|
||||||
|
offset += 100
|
||||||
|
if offset > 0x1F940:
|
||||||
|
offset = 0
|
||||||
|
|
||||||
|
return chars
|
||||||
|
|
||||||
|
def benchmark_unicode_script(self):
|
||||||
|
with session.Session(config=benchmark.benchmark_config()) as sess:
|
||||||
|
chars = self._generateBenchmarkInput(1000000)
|
||||||
|
script = string_ops.unicode_script(chars)
|
||||||
|
self.run_op_benchmark(sess, script.op, min_iters=100)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test.main()
|
test.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user