Basic Usage
A decorator for measuring asynchronous/synchronous function execution time (in seconds) is offered by this Python module.
- 1st parameter: total number of iterations of the function. defaults to 1.
- 2nd parameter: (int, optional): precision of execution time in seconds. defaults to 5.
- 3rd parameter: (bool, optional): whether each function execution time is printed. defaults to true.
Example 1: synonymous function
from sandclock import sandclock
@sandclock(3) #execute f1() 3 times.
def f1(x):
print("f1: ", x)
f1("hello world")
Results:
Sandclock: synchronous <function f1 at 0x7f89eaca7e50> with args ('hello world',) {}
Sandclock: iteration: 0 started, <function f1 at 0x7f89eaca7e50> with args ('hello world',) {}
f1: hello world
Sandclock: iteration: 0 finished, <function f1 at 0x7f89eaca7e50> in 0.000823 second(s)
Sandclock: iteration: 1 started, <function f1 at 0x7f89eaca7e50> with args ('hello world',) {}
f1: hello world
Sandclock: iteration: 1 finished, <function f1 at 0x7f89eaca7e50> in 0.000075 second(s)
Sandclock: iteration: 2 started, <function f1 at 0x7f89eaca7e50> with args ('hello world',) {}
f1: hello world
Sandclock: iteration: 2 finished, <function f1 at 0x7f89eaca7e50> in 0.000151 second(s)
Sandclock: total time: 0.001050, total iterations: 3```
Example 2: (Asynchronous function)
import aiohttp
import asyncio
from sandclock import sandclock
async def status(session: aiohttp.ClientSession, url: str) -> int:
async with session.get(url) as result:
return result.status
#execute f2() 2 times, 3 precisions, printing details of each function call.
@sandclock(2, 3, True)
async def f2():
async with aiohttp.ClientSession() as session:
urls = ['https://google.com', 'xxx://bad-request.com']
tasks = [status(session, url) for url in urls]
results = await asyncio.gather(*tasks, return_exceptions=True)
exceptions = [res for res in results if isinstance(res, Exception)]
successful_results = [res for res in results if not isinstance(res, Exception)]
print(f'All results: {results}')
print(f'Finished successfully: {successful_results}')
print(f'Threw exceptions: {exceptions}')
asyncio.run(f2())
Results:
Sandclock: coroutine <function f2 at 0x7f632fd3e430> with args () {}
Sandclock: iteration: 0 started, <function f2 at 0x7f632fd3e430> with args () {}
All results: [200, AssertionError()]
Finished successfully: [200]
Threw exceptions: [AssertionError()]
Sandclock: iteration: 0 finished, <function f2 at 0x7f632fd3e430> in 2.400 second(s)
Sandclock: iteration: 1 started, <function f2 at 0x7f632fd3e430> with args () {}
All results: [200, AssertionError()]
Finished successfully: [200]
Threw exceptions: [AssertionError()]
Sandclock: iteration: 1 finished, <function f2 at 0x7f632fd3e430> in 2.385 second(s)
Sandclock: total time: 4.785 second(s), total iterations: 2
Metadata
Release files for sandclock 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sandclock-0.1.3.tar.gz | 3.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sandclock-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.0 kB
Release files / sandclock-0.1.3.tar.gz
| Download URL | sandclock-0.1.3.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b885f76f880b87e742daca93abd64de646b2fa16b973c20654b30dfc5363e5d2
|
|
BLAKE2b-256 checksum How to use checksums |
86ca24820bd085876997cf1ddead7a237820639328b4b40e8664b29273ed48f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.8.10 Linux/5.10.16.3-microsoft-standard-WSL2
|
Release files / sandclock-0.1.3-py3-none-any.whl
| Download URL | sandclock-0.1.3-py3-none-any.whl |
|---|---|
| Size | 3.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
664ce6dec7c656e5d68036a49b7960c8e069b803e29a69d02e8866146e278811
|
|
BLAKE2b-256 checksum How to use checksums |
09dd3c5b9fb23fdbe886da322728b266e971d02f29f0b399d9ea3f85b95bd65f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.8.10 Linux/5.10.16.3-microsoft-standard-WSL2
|
Security for sandclock 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.