timer-for-python


Nametimer-for-python JSON
Version 0.7.3 PyPI version JSON
download
home_pagehttps://jakob-bagterp.github.io/timer-for-python/
SummaryTimer for Python
upload_time2024-04-08 23:47:44
maintainerJakob Bagterp
docs_urlNone
authorJakob Bagterp
requires_python>=3.10
licenseMIT License
keywords python timer
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Latest version](https://img.shields.io/static/v1?label=version&message=0.7.3&color=yellowgreen)](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
[![Python 3.10 | 3.11 | 3.12+](https://img.shields.io/static/v1?label=python&message=3.10%20|%203.11%20|%203.12%2B&color=blueviolet)](https://www.python.org)
[![MIT license](https://img.shields.io/static/v1?label=license&message=MIT&color=blue)](https://github.com/jakob-bagterp/timer-for-python/blob/master/LICENSE.md)
[![Codecov](https://codecov.io/gh/jakob-bagterp/timer-for-python/branch/master/graph/badge.svg?token=P4IT8WQO0R)](https://codecov.io/gh/jakob-bagterp/timer-for-python)
[![CodeQL](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/codeql.yml/badge.svg)](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/codeql.yml)
[![Test](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/test.yml/badge.svg)](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/test.yml)
[![Downloads](https://static.pepy.tech/badge/timer-for-python)](https://pepy.tech/project/timer-for-python)

# ⏳ Timer for Python ⌛️
Lightweight Python package that makes it easy to measure how much time it takes to run Python programs and gauge performance of multiple, smaller bits of code.

Ready to try? Learn [how to install](https://jakob-bagterp.github.io/timer-for-python/getting-started/installation/) and find tutorials in the [user guide](https://jakob-bagterp.github.io/timer-for-python/user-guide/).

## Getting Started
### Basics
Simply add the Timer to your imports, and then wrap the Timer function around your code to measure the performance of the executed block of code:

```python
from timer import Timer

timer = Timer()
timer.start()

# Insert your code here

timer.stop() # Output example: 12.34 seconds
```

#### Context Manager
Alternatively, use the with statement. This will automatically start and stop the Timer – and so no need to declare `timer.start()` and `timer.stop()`. Same result as before, but less code:

```python
with Timer():
    # Insert your code here

    # Output example: 12.34 seconds
```

#### Decorator
Or use the `benchmark_timer` as a function decorator:

```python
from timer import benchmark_timer

@benchmark_timer
def test_function():
    # Insert your code here

test_function()

# Output example: 12.34 seconds for thread TEST_FUNCTION
```

### Core Features
#### Decimals
Instead of the default value of `2` for `decimals``, you can set the output precision up to `9` in the `decimals` argument:

```python
timer = Timer()
timer.start(decimals=5)

# Insert your code here

timer.stop() # Output example: 0.12345 seconds
```

#### Multiple Threads
Imagine that you want to troubleshoot which parts of your code are performing better or worse. Or do you want to split-test the performance of different methods? Timer for Python is a quick, easy way to get the job done.

To measure the performance of multiple blocks of code, use the `thread` argument to name different threads:

```python
timer = Timer()
timer.start(thread="A")

# Insert your code here

    timer.start(thread="B", decimals=5)

    # Insert more code here

    timer.stop(thread="B") # Output example: 0.12345 seconds for thread B

# Insert even more code here

timer.stop(thread="A") # Output example: 6.78 seconds for thread A
```

Or use the `with` statement to get the same result with less code:
```python
with Timer(thread="A")
    # Insert your code here

    with Timer(thread="B", decimals=5):
        # Insert more code here

        # Output example: 0.12345 seconds for thread B

    # Insert even more code here

    # Output example: 6.78 seconds for thread A
```

# Thank You for Supporting
## Donate
This module is free to use. And if you like it, feel free to [buy me a coffee](https://github.com/sponsors/jakob-bagterp).

## Contribute
If you have suggestions or changes to the module, feel free to add to the code and create a [pull request](https://github.com/jakob-bagterp/timer-for-python/pulls).

## Report Bugs
Report bugs and issues [here](https://github.com/jakob-bagterp/timer-for-python/issues).

# MIT License

Copyright (c) 2020 – present, Jakob Bagterp

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

            

Raw data

            {
    "_id": null,
    "home_page": "https://jakob-bagterp.github.io/timer-for-python/",
    "name": "timer-for-python",
    "maintainer": "Jakob Bagterp",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "jakob_bagterp@hotmail.com",
    "keywords": "python, timer",
    "author": "Jakob Bagterp",
    "author_email": "jakob_bagterp@hotmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c2/e2/c980e82d9252bc7d78ff572606d8d9a245aaf50c6381bc00a71221cb0f71/timer-for-python-0.7.3.tar.gz",
    "platform": null,
    "description": "[![Latest version](https://img.shields.io/static/v1?label=version&message=0.7.3&color=yellowgreen)](https://github.com/jakob-bagterp/timer-for-python/releases/latest)\n[![Python 3.10 | 3.11 | 3.12+](https://img.shields.io/static/v1?label=python&message=3.10%20|%203.11%20|%203.12%2B&color=blueviolet)](https://www.python.org)\n[![MIT license](https://img.shields.io/static/v1?label=license&message=MIT&color=blue)](https://github.com/jakob-bagterp/timer-for-python/blob/master/LICENSE.md)\n[![Codecov](https://codecov.io/gh/jakob-bagterp/timer-for-python/branch/master/graph/badge.svg?token=P4IT8WQO0R)](https://codecov.io/gh/jakob-bagterp/timer-for-python)\n[![CodeQL](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/codeql.yml/badge.svg)](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/codeql.yml)\n[![Test](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/test.yml/badge.svg)](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/test.yml)\n[![Downloads](https://static.pepy.tech/badge/timer-for-python)](https://pepy.tech/project/timer-for-python)\n\n# \u23f3 Timer for Python \u231b\ufe0f\nLightweight Python package that makes it easy to measure how much time it takes to run Python programs and gauge performance of multiple, smaller bits of code.\n\nReady to try? Learn [how to install](https://jakob-bagterp.github.io/timer-for-python/getting-started/installation/) and find tutorials in the [user guide](https://jakob-bagterp.github.io/timer-for-python/user-guide/).\n\n## Getting Started\n### Basics\nSimply add the Timer to your imports, and then wrap the Timer function around your code to measure the performance of the executed block of code:\n\n```python\nfrom timer import Timer\n\ntimer = Timer()\ntimer.start()\n\n# Insert your code here\n\ntimer.stop() # Output example: 12.34 seconds\n```\n\n#### Context Manager\nAlternatively, use the with statement. This will automatically start and stop the Timer \u2013 and so no need to declare `timer.start()` and `timer.stop()`. Same result as before, but less code:\n\n```python\nwith Timer():\n    # Insert your code here\n\n    # Output example: 12.34 seconds\n```\n\n#### Decorator\nOr use the `benchmark_timer` as a function decorator:\n\n```python\nfrom timer import benchmark_timer\n\n@benchmark_timer\ndef test_function():\n    # Insert your code here\n\ntest_function()\n\n# Output example: 12.34 seconds for thread TEST_FUNCTION\n```\n\n### Core Features\n#### Decimals\nInstead of the default value of `2` for `decimals``, you can set the output precision up to `9` in the `decimals` argument:\n\n```python\ntimer = Timer()\ntimer.start(decimals=5)\n\n# Insert your code here\n\ntimer.stop() # Output example: 0.12345 seconds\n```\n\n#### Multiple Threads\nImagine that you want to troubleshoot which parts of your code are performing better or worse. Or do you want to split-test the performance of different methods? Timer for Python is a quick, easy way to get the job done.\n\nTo measure the performance of multiple blocks of code, use the `thread` argument to name different threads:\n\n```python\ntimer = Timer()\ntimer.start(thread=\"A\")\n\n# Insert your code here\n\n    timer.start(thread=\"B\", decimals=5)\n\n    # Insert more code here\n\n    timer.stop(thread=\"B\") # Output example: 0.12345 seconds for thread B\n\n# Insert even more code here\n\ntimer.stop(thread=\"A\") # Output example: 6.78 seconds for thread A\n```\n\nOr use the `with` statement to get the same result with less code:\n```python\nwith Timer(thread=\"A\")\n    # Insert your code here\n\n    with Timer(thread=\"B\", decimals=5):\n        # Insert more code here\n\n        # Output example: 0.12345 seconds for thread B\n\n    # Insert even more code here\n\n    # Output example: 6.78 seconds for thread A\n```\n\n# Thank You for Supporting\n## Donate\nThis module is free to use. And if you like it, feel free to [buy me a coffee](https://github.com/sponsors/jakob-bagterp).\n\n## Contribute\nIf you have suggestions or changes to the module, feel free to add to the code and create a [pull request](https://github.com/jakob-bagterp/timer-for-python/pulls).\n\n## Report Bugs\nReport bugs and issues [here](https://github.com/jakob-bagterp/timer-for-python/issues).\n\n# MIT License\n\nCopyright (c) 2020 \u2013 present, Jakob Bagterp\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Timer for Python",
    "version": "0.7.3",
    "project_urls": {
        "API Reference": "https://jakob-bagterp.github.io/timer-for-python/reference/",
        "Bug Tracker": "https://github.com/jakob-bagterp/timer-for-python/issues",
        "Documentation": "https://jakob-bagterp.github.io/timer-for-python/",
        "Download": "https://pypi.org/project/timer-for-python/",
        "Homepage": "https://jakob-bagterp.github.io/timer-for-python/",
        "Release Notes": "https://github.com/jakob-bagterp/timer-for-python/releases",
        "Source Code": "https://github.com/jakob-bagterp/timer-for-python"
    },
    "split_keywords": [
        "python",
        " timer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9c8472c6c1a942cb3e9d7adf607f7af582d595b0b17da9f4b5de5a48aba22b14",
                "md5": "95526e048629d873f139e03290e99716",
                "sha256": "51dc169c3247d1dc1274187938a62b01ccec47f73135e17a253b85bd9f9d1574"
            },
            "downloads": -1,
            "filename": "timer_for_python-0.7.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "95526e048629d873f139e03290e99716",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 14312,
            "upload_time": "2024-04-08T23:47:43",
            "upload_time_iso_8601": "2024-04-08T23:47:43.083928Z",
            "url": "https://files.pythonhosted.org/packages/9c/84/72c6c1a942cb3e9d7adf607f7af582d595b0b17da9f4b5de5a48aba22b14/timer_for_python-0.7.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c2e2c980e82d9252bc7d78ff572606d8d9a245aaf50c6381bc00a71221cb0f71",
                "md5": "64e5bb6a0b51644d62585db89fdbc8ff",
                "sha256": "1411f4531ecb4e12197e019d10b5dfed653ea83e2cd13619852a05b915664fc3"
            },
            "downloads": -1,
            "filename": "timer-for-python-0.7.3.tar.gz",
            "has_sig": false,
            "md5_digest": "64e5bb6a0b51644d62585db89fdbc8ff",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 12421,
            "upload_time": "2024-04-08T23:47:44",
            "upload_time_iso_8601": "2024-04-08T23:47:44.706420Z",
            "url": "https://files.pythonhosted.org/packages/c2/e2/c980e82d9252bc7d78ff572606d8d9a245aaf50c6381bc00a71221cb0f71/timer-for-python-0.7.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-08 23:47:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jakob-bagterp",
    "github_project": "timer-for-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "timer-for-python"
}
        
Elapsed time: 0.28563s