From a5218db824d7c7d7221e5296c0cf6e9cc7c14b48 Mon Sep 17 00:00:00 2001 From: norohind <60548839+norohind@users.noreply.github.com> Date: Sat, 27 Nov 2021 00:51:28 +0300 Subject: [PATCH] @utils.measure decorator for debug purposes --- utils.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/utils.py b/utils.py index 246f877..a14cf29 100644 --- a/utils.py +++ b/utils.py @@ -150,6 +150,29 @@ def build_index_page(app: falcon.App, index_path: str) -> None: index_file.write(index_template.format(body=app_info_str)) +def measure(function: callable): + """ + Decorator to measure function (method) execution time + Use as easy as + + @utils.measure + def im_function_to_measure(): + .... + + :param function: + :return: + """ + + def decorated(*args, **kwargs): + start = time.time() + result = function(*args, **kwargs) + end = time.time() + print(f'{function.__name__}: {(end - start) * 100} ms') + return result + + return decorated + + activity_table_html_template = """