Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function that print each function's execution time #1174

Merged
merged 1 commit into from
Feb 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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