diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2023-08-28 22:08:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-28 22:08:23 +0200 |
commit | 7e687b3d178c00a27d7e5ae2613fe88ee7844639 (patch) | |
tree | 4034e8ae9fc7ca9af295f04358bb00516b464e0b /testing/log_time.py | |
parent | Merge pull request #851 from Luneye/patch-1 (diff) | |
parent | Merge branch 'main' into hugging (diff) | |
download | gpt4free-7e687b3d178c00a27d7e5ae2613fe88ee7844639.tar gpt4free-7e687b3d178c00a27d7e5ae2613fe88ee7844639.tar.gz gpt4free-7e687b3d178c00a27d7e5ae2613fe88ee7844639.tar.bz2 gpt4free-7e687b3d178c00a27d7e5ae2613fe88ee7844639.tar.lz gpt4free-7e687b3d178c00a27d7e5ae2613fe88ee7844639.tar.xz gpt4free-7e687b3d178c00a27d7e5ae2613fe88ee7844639.tar.zst gpt4free-7e687b3d178c00a27d7e5ae2613fe88ee7844639.zip |
Diffstat (limited to 'testing/log_time.py')
-rw-r--r-- | testing/log_time.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/testing/log_time.py b/testing/log_time.py new file mode 100644 index 00000000..376ab86d --- /dev/null +++ b/testing/log_time.py @@ -0,0 +1,25 @@ +from time import time + + +async def log_time_async(method: callable, **kwargs): + start = time() + result = await method(**kwargs) + secs = f"{round(time() - start, 2)} secs" + if result: + return " ".join([result, secs]) + return secs + + +def log_time_yield(method: callable, **kwargs): + start = time() + result = yield from method(**kwargs) + yield f" {round(time() - start, 2)} secs" + + +def log_time(method: callable, **kwargs): + start = time() + result = method(**kwargs) + secs = f"{round(time() - start, 2)} secs" + if result: + return " ".join([result, secs]) + return secs
\ No newline at end of file |