Skip to content

Commit

Permalink
[Utils] Function for timing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Squadrick committed Feb 27, 2020
1 parent 92b5d25 commit f53e6c6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tensorflow_addons/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import contextlib
import inspect
import time
import unittest

import tensorflow as tf
Expand Down Expand Up @@ -160,3 +161,24 @@ def decorated(self, *args, **kwargs):
return decorated

return decorator


def time_function(f):
def decorated(self, *args, **kwargs):
start = time.time()
f(self, *args, **kwargs)
end = time.time()
print(f.__name__, "took", (end - start), "seconds")

return decorated


def time_all_functions(cls):
for name, method in cls.__dict__.copy().items():
if (
callable(method)
and name.startswith(unittest.TestLoader.testMethodPrefix)
and name != "test_session"
):
setattr(cls, name, time_function(method))
return cls

0 comments on commit f53e6c6

Please sign in to comment.