Skip to content

Commit

Permalink
Add benchmark for unicode_script op.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 243111734
  • Loading branch information
gregbillock authored and tensorflower-gardener committed Apr 11, 2019
1 parent 826a245 commit 1b206c1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tensorflow/python/kernel_tests/unicode_script_op_test.py
Expand Up @@ -18,10 +18,12 @@
from __future__ import division
from __future__ import print_function

from tensorflow.python.client import session
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import test_util
from tensorflow.python.ops import string_ops
from tensorflow.python.platform import benchmark
from tensorflow.python.platform import test


Expand Down Expand Up @@ -56,5 +58,31 @@ def testInvalidScript(self):
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__":
test.main()

0 comments on commit 1b206c1

Please sign in to comment.