diff options
author | Ryan Jordan <ryjordan@gmail.com> | 2023-09-06 02:39:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-06 02:39:57 +0200 |
commit | f81e618958318a092ca4c70a1b3ea15260bda97c (patch) | |
tree | 3ce022a8d719011268da7f1a0befc97bf32a60d8 /testing/log_time.py | |
parent | feat(docker): add Docker and Docker Compose support (diff) | |
parent | ~ | Merge pull request #869 from ahobsonsayers/add-console-script (diff) | |
download | gpt4free-f81e618958318a092ca4c70a1b3ea15260bda97c.tar gpt4free-f81e618958318a092ca4c70a1b3ea15260bda97c.tar.gz gpt4free-f81e618958318a092ca4c70a1b3ea15260bda97c.tar.bz2 gpt4free-f81e618958318a092ca4c70a1b3ea15260bda97c.tar.lz gpt4free-f81e618958318a092ca4c70a1b3ea15260bda97c.tar.xz gpt4free-f81e618958318a092ca4c70a1b3ea15260bda97c.tar.zst gpt4free-f81e618958318a092ca4c70a1b3ea15260bda97c.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..7d268128 --- /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 |