jazzy-timer


Namejazzy-timer JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/edward-jazzhands/jazzy_timer
SummaryAn ultra-simple timer decorator, part of the jazzy utilities series.
upload_time2024-08-18 00:08:47
maintainerNone
docs_urlNone
authorEdward Jazzhands
requires_python<4.0,>=3.10
licenseMIT
keywords timer timing decorator profiling profiler benchmark jazzy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## jazzy-timer

Installation:
```
pip install jazzy-timer
```

*#1 in the "jazzy" utilities series by Edward Jazzhands.*
*Currently the only one in the series. More to come...*

A very simple timer that will return a tuple consisting of:
1) The result of the function call
2) The result of the timer (as a float)
   
This makes it much easier to format it to whatever you want, or use it for statistics:
- Send the two variables to different outputs (ie. send elapsed time to log output)
- Toggle displaying elapsed time on/off without removing the decorator.
- Compare times with other functions using math operators.
- Store the elapsed time in a database and sort ascending/descending.
- etc

### Why?

I found that the other simple timer libraries on PyPI do not work this way, and feel more convulted to use. 
This version is designed to be ultra-simple, and easier to integrate with other log systems you might be using.

### Examples:

Basic usage:
```
from jazzy-timer import timer

@timer
def func_to_be_timed():
    return something

result, elapsed_time = func_to_be_timed()   # returns a tuple

print(f"Result of function call: {result}")   # use function results as normal
logging.info("Ran func_to_be_timed with elapsed time: %s", elapsed_time)    # print elapsed time elsewhere
```

You can also set the timer precision (default is 4 decimal places). Timer can be used with or without this additional argument:
```
@timer(precision=2)
def func_to_be_timed():
    return something
```

If the function itself returns a tuple, you'll have a nested tuple:
```
@timer
def test_function(time_to_sleep):

    time.sleep(time_to_sleep)
    return "some result", 33

result_tuple, elapsed_time = test_function(0.543)
print(f"Result of function call: {result_tuple} | Elapsed time: {elapsed_time} seconds")
```
OUTPUT:
```
Result of function call: ('some result', 33) | Elapsed time: 0.5436 seconds
```
In this scenario, simply unpack the nested tuple in a separate step.

Thats it! There's nothing else to memorize. There's also no dependencies, it only uses standard library.

*All utilities in the "jazzy" series follow the Radical Simplicity design philosophy.*


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/edward-jazzhands/jazzy_timer",
    "name": "jazzy-timer",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "timer, timing, decorator, profiling, profiler, benchmark, jazzy",
    "author": "Edward Jazzhands",
    "author_email": "ed.jazzhands@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/97/52/91b9e0faffad44a6f89cdca46c4569d87cd697a6180e99d88e0dd7d54941/jazzy_timer-0.2.0.tar.gz",
    "platform": null,
    "description": "## jazzy-timer\n\nInstallation:\n```\npip install jazzy-timer\n```\n\n*#1 in the \"jazzy\" utilities series by Edward Jazzhands.*\n*Currently the only one in the series. More to come...*\n\nA very simple timer that will return a tuple consisting of:\n1) The result of the function call\n2) The result of the timer (as a float)\n   \nThis makes it much easier to format it to whatever you want, or use it for statistics:\n- Send the two variables to different outputs (ie. send elapsed time to log output)\n- Toggle displaying elapsed time on/off without removing the decorator.\n- Compare times with other functions using math operators.\n- Store the elapsed time in a database and sort ascending/descending.\n- etc\n\n### Why?\n\nI found that the other simple timer libraries on PyPI do not work this way, and feel more convulted to use. \nThis version is designed to be ultra-simple, and easier to integrate with other log systems you might be using.\n\n### Examples:\n\nBasic usage:\n```\nfrom jazzy-timer import timer\n\n@timer\ndef func_to_be_timed():\n    return something\n\nresult, elapsed_time = func_to_be_timed()   # returns a tuple\n\nprint(f\"Result of function call: {result}\")   # use function results as normal\nlogging.info(\"Ran func_to_be_timed with elapsed time: %s\", elapsed_time)    # print elapsed time elsewhere\n```\n\nYou can also set the timer precision (default is 4 decimal places). Timer can be used with or without this additional argument:\n```\n@timer(precision=2)\ndef func_to_be_timed():\n    return something\n```\n\nIf the function itself returns a tuple, you'll have a nested tuple:\n```\n@timer\ndef test_function(time_to_sleep):\n\n    time.sleep(time_to_sleep)\n    return \"some result\", 33\n\nresult_tuple, elapsed_time = test_function(0.543)\nprint(f\"Result of function call: {result_tuple} | Elapsed time: {elapsed_time} seconds\")\n```\nOUTPUT:\n```\nResult of function call: ('some result', 33) | Elapsed time: 0.5436 seconds\n```\nIn this scenario, simply unpack the nested tuple in a separate step.\n\nThats it! There's nothing else to memorize. There's also no dependencies, it only uses standard library.\n\n*All utilities in the \"jazzy\" series follow the Radical Simplicity design philosophy.*\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An ultra-simple timer decorator, part of the jazzy utilities series.",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/edward-jazzhands/jazzy_timer",
        "Repository": "https://github.com/edward-jazzhands/jazzy_timer"
    },
    "split_keywords": [
        "timer",
        " timing",
        " decorator",
        " profiling",
        " profiler",
        " benchmark",
        " jazzy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ee991eba1b44a58f41b43c1f2ff6f294c42c70005a8bc51f714c062bbbc867a4",
                "md5": "f3420d05019d93338cb3cf6809594b97",
                "sha256": "08202fcaee2eb24bf4a8fb24914e8f068bfc66152881edd5a5a2a6cc63caaea7"
            },
            "downloads": -1,
            "filename": "jazzy_timer-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f3420d05019d93338cb3cf6809594b97",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 4685,
            "upload_time": "2024-08-18T00:08:46",
            "upload_time_iso_8601": "2024-08-18T00:08:46.201780Z",
            "url": "https://files.pythonhosted.org/packages/ee/99/1eba1b44a58f41b43c1f2ff6f294c42c70005a8bc51f714c062bbbc867a4/jazzy_timer-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "975291b9e0faffad44a6f89cdca46c4569d87cd697a6180e99d88e0dd7d54941",
                "md5": "deae210bdf0b636eaab2058aa0e306e8",
                "sha256": "ae6b5e1dc4b074eabdc53f1f0e7946ef166f4adab7e6c2cc621bd83db2fba3bd"
            },
            "downloads": -1,
            "filename": "jazzy_timer-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "deae210bdf0b636eaab2058aa0e306e8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 3384,
            "upload_time": "2024-08-18T00:08:47",
            "upload_time_iso_8601": "2024-08-18T00:08:47.643998Z",
            "url": "https://files.pythonhosted.org/packages/97/52/91b9e0faffad44a6f89cdca46c4569d87cd697a6180e99d88e0dd7d54941/jazzy_timer-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-18 00:08:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "edward-jazzhands",
    "github_project": "jazzy_timer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "jazzy-timer"
}
        
Elapsed time: 1.03042s