python-stopwatch


Namepython-stopwatch JSON
Version 1.1.11 PyPI version JSON
download
home_pagehttps://github.com/jonghwanhyeon/python-stopwatch
SummaryA simple stopwatch for measuring code performance
upload_time2024-07-14 06:33:40
maintainerNone
docs_urlNone
authorJonghwan Hyeon
requires_python>=3.7
licenseMIT
keywords stopwatch profile
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Stopwatch

A simple stopwatch for measuring code performance.

## Installing

To install the library, you can just run the following command:

```shell
$ python3 -m pip install python-stopwatch
```

## Examples

```python
import time
from stopwatch import Stopwatch, profile

stopwatch = Stopwatch()
stopwatch.start()
time.sleep(3.0)
stopwatch.stop()
print(stopwatch.elapsed)
# 3.003047182224691

with Stopwatch(name="outer") as outer_stopwatch:
    with Stopwatch(name="inner") as inner_stopwatch:
        for i in range(5):
            with inner_stopwatch.lap():
                time.sleep(i / 10)
print(inner_stopwatch.elapsed)
# 1.0013675531372428
print(inner_stopwatch.laps)
# [5.3666066378355026e-05, 0.10502862487919629, 0.202481625135988, 0.30503024999052286, 0.4007756249047816]
print(outer_stopwatch.report())
# [Stopwatch#outer] total=1.0135s, mean=1.0135s, min=1.0135s, median=1.0135s, max=1.0135s
print(inner_stopwatch.report())
# [Stopwatch#inner] total=1.0134s, mean=0.2027s, min=0.05ms, median=0.2025s, max=0.4008s, stdev=0.1584s
```

```python
import time
from stopwatch import profile

@profile
def wait_for(ts):
    if not ts:
        return

    time.sleep(ts[0])
    wait_for(ts[1:])

wait_for([0.1, 0.2, 0.3, 0.4, 0.5])
# [__main__:wait_for] hits=1, total=0.00ms, mean=0.00ms, min=0.00ms, median=0.00ms, max=0.00ms
# [__main__:wait_for] hits=2, total=0.5015s, mean=0.2508s, min=0.00ms, median=0.2508s, max=0.5015s, stdev=0.3546s
# [__main__:wait_for] hits=3, total=1.4050s, mean=0.4683s, min=0.00ms, median=0.5015s, max=0.9034s, stdev=0.4526s
# [__main__:wait_for] hits=4, total=2.6110s, mean=0.6528s, min=0.00ms, median=0.7025s, max=1.2060s, stdev=0.5222s
# [__main__:wait_for] hits=5, total=4.0223s, mean=0.8045s, min=0.00ms, median=0.9034s, max=1.4113s, stdev=0.5653s
# [__main__:wait_for] hits=6, total=5.5354s, mean=0.9226s, min=0.00ms, median=1.0547s, max=1.5131s, stdev=0.5825s
# [__main__:wait_for] hits=6, total=5.5354s, mean=0.9226s, min=0.00ms, median=1.0547s, max=1.5131s, stdev=0.5825s
```

```python
import time
from stopwatch import profile

@profile("wait for ts")
def wait_for(ts):
    if not ts:
        return

    time.sleep(ts[0])
    wait_for(ts[1:])

wait_for([0.1, 0.2, 0.3, 0.4, 0.5])
# [__main__:wait for ts] hits=1, total=0.00ms, mean=0.00ms, min=0.00ms, median=0.00ms, max=0.00ms
# [__main__:wait for ts] hits=2, total=0.5041s, mean=0.2520s, min=0.00ms, median=0.2520s, max=0.5041s, stdev=0.3564s
# [__main__:wait for ts] hits=3, total=1.4133s, mean=0.4711s, min=0.00ms, median=0.5041s, max=0.9093s, stdev=0.4555s
# [__main__:wait for ts] hits=4, total=2.6385s, mean=0.6596s, min=0.00ms, median=0.7067s, max=1.2252s, stdev=0.5296s
# [__main__:wait for ts] hits=5, total=4.0690s, mean=0.8138s, min=0.00ms, median=0.9093s, max=1.4305s, stdev=0.5738s
# [__main__:wait for ts] hits=6, total=5.6026s, mean=0.9338s, min=0.00ms, median=1.0672s, max=1.5336s, stdev=0.5914s
# [__main__:wait for ts] hits=6, total=5.6026s, mean=0.9338s, min=0.00ms, median=1.0672s, max=1.5336s, stdev=0.5914s
```

```python
import time
from stopwatch import profile

@profile("wait for ts", report_every=2)
def wait_for(ts):
    if not ts:
        return

    time.sleep(ts[0])
    wait_for(ts[1:])

wait_for([0.1, 0.2, 0.3, 0.4, 0.5])
# [__main__:wait for ts] hits=2, total=0.5034s, mean=0.2517s, min=0.02ms, median=0.2517s, max=0.5034s, stdev=0.3559s
# [__main__:wait for ts] hits=4, total=2.6276s, mean=0.6569s, min=0.02ms, median=0.7065s, max=1.2146s, stdev=0.5260s
# [__main__:wait for ts] hits=6, total=5.5693s, mean=0.9282s, min=0.02ms, median=1.0621s, max=1.5221s, stdev=0.5863s
# [__main__:wait for ts] hits=6, total=5.5693s, mean=0.9282s, min=0.02ms, median=1.0621s, max=1.5221s, stdev=0.5863s
```

```python
import time
from stopwatch import profile

@profile("wait for ts", report_every=None)
def wait_for(ts):
    if not ts:
        return

    time.sleep(ts[0])
    wait_for(ts[1:])

wait_for([0.1, 0.2, 0.3, 0.4, 0.5])
# [__main__:wait for ts] hits=6, total=5.5361s, mean=0.9227s, min=0.00ms, median=1.0554s, max=1.5145s, stdev=0.5827s
```

```python
import time
from stopwatch import profile

@profile(
    "wait for ts",
    format="<bold>[<blue>{module}</blue>:<green>{name}</green>]</bold> {statistics:hits, mean, median, stdev}",
)
def wait_for(ts):
    if not ts:
        return

    time.sleep(ts[0])
    wait_for(ts[1:])

wait_for([0.1, 0.2, 0.3, 0.4, 0.5])
# [__main__:wait for ts] hits=1, mean=0.01ms, median=0.01ms
# [__main__:wait for ts] hits=2, mean=0.2527s, median=0.2527s, stdev=0.3573s
# [__main__:wait for ts] hits=3, mean=0.4720s, median=0.5053s, stdev=0.4562s
# [__main__:wait for ts] hits=4, mean=0.6579s, median=0.7079s, stdev=0.5263s
# [__main__:wait for ts] hits=5, mean=0.8096s, median=0.9105s, stdev=0.5682s
# [__main__:wait for ts] hits=6, mean=0.9282s, median=1.0631s, stdev=0.5854s
# [__main__:wait for ts] hits=6, mean=0.9282s, median=1.0631s, stdev=0.5854s
```

```python
import time
from stopwatch import stopwatch

with stopwatch():
    for i in range(5):
        time.sleep(i / 10)
# [__main__:<module>:L5] ~ 1.0013s


with stopwatch("with message"):
    for i in range(5):
        time.sleep(i / 10)
# [__main__:<module>:L11] ~ 1.0013s - with message
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jonghwanhyeon/python-stopwatch",
    "name": "python-stopwatch",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "stopwatch, profile",
    "author": "Jonghwan Hyeon",
    "author_email": "jonghwanhyeon93@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7c/3a/68c18be11ad5a84599ae3318f9659a46cc93ebb0322257a17f8e50441880/python_stopwatch-1.1.11.tar.gz",
    "platform": null,
    "description": "# Stopwatch\n\nA simple stopwatch for measuring code performance.\n\n## Installing\n\nTo install the library, you can just run the following command:\n\n```shell\n$ python3 -m pip install python-stopwatch\n```\n\n## Examples\n\n```python\nimport time\nfrom stopwatch import Stopwatch, profile\n\nstopwatch = Stopwatch()\nstopwatch.start()\ntime.sleep(3.0)\nstopwatch.stop()\nprint(stopwatch.elapsed)\n# 3.003047182224691\n\nwith Stopwatch(name=\"outer\") as outer_stopwatch:\n    with Stopwatch(name=\"inner\") as inner_stopwatch:\n        for i in range(5):\n            with inner_stopwatch.lap():\n                time.sleep(i / 10)\nprint(inner_stopwatch.elapsed)\n# 1.0013675531372428\nprint(inner_stopwatch.laps)\n# [5.3666066378355026e-05, 0.10502862487919629, 0.202481625135988, 0.30503024999052286, 0.4007756249047816]\nprint(outer_stopwatch.report())\n# [Stopwatch#outer] total=1.0135s, mean=1.0135s, min=1.0135s, median=1.0135s, max=1.0135s\nprint(inner_stopwatch.report())\n# [Stopwatch#inner] total=1.0134s, mean=0.2027s, min=0.05ms, median=0.2025s, max=0.4008s, stdev=0.1584s\n```\n\n```python\nimport time\nfrom stopwatch import profile\n\n@profile\ndef wait_for(ts):\n    if not ts:\n        return\n\n    time.sleep(ts[0])\n    wait_for(ts[1:])\n\nwait_for([0.1, 0.2, 0.3, 0.4, 0.5])\n# [__main__:wait_for] hits=1, total=0.00ms, mean=0.00ms, min=0.00ms, median=0.00ms, max=0.00ms\n# [__main__:wait_for] hits=2, total=0.5015s, mean=0.2508s, min=0.00ms, median=0.2508s, max=0.5015s, stdev=0.3546s\n# [__main__:wait_for] hits=3, total=1.4050s, mean=0.4683s, min=0.00ms, median=0.5015s, max=0.9034s, stdev=0.4526s\n# [__main__:wait_for] hits=4, total=2.6110s, mean=0.6528s, min=0.00ms, median=0.7025s, max=1.2060s, stdev=0.5222s\n# [__main__:wait_for] hits=5, total=4.0223s, mean=0.8045s, min=0.00ms, median=0.9034s, max=1.4113s, stdev=0.5653s\n# [__main__:wait_for] hits=6, total=5.5354s, mean=0.9226s, min=0.00ms, median=1.0547s, max=1.5131s, stdev=0.5825s\n# [__main__:wait_for] hits=6, total=5.5354s, mean=0.9226s, min=0.00ms, median=1.0547s, max=1.5131s, stdev=0.5825s\n```\n\n```python\nimport time\nfrom stopwatch import profile\n\n@profile(\"wait for ts\")\ndef wait_for(ts):\n    if not ts:\n        return\n\n    time.sleep(ts[0])\n    wait_for(ts[1:])\n\nwait_for([0.1, 0.2, 0.3, 0.4, 0.5])\n# [__main__:wait for ts] hits=1, total=0.00ms, mean=0.00ms, min=0.00ms, median=0.00ms, max=0.00ms\n# [__main__:wait for ts] hits=2, total=0.5041s, mean=0.2520s, min=0.00ms, median=0.2520s, max=0.5041s, stdev=0.3564s\n# [__main__:wait for ts] hits=3, total=1.4133s, mean=0.4711s, min=0.00ms, median=0.5041s, max=0.9093s, stdev=0.4555s\n# [__main__:wait for ts] hits=4, total=2.6385s, mean=0.6596s, min=0.00ms, median=0.7067s, max=1.2252s, stdev=0.5296s\n# [__main__:wait for ts] hits=5, total=4.0690s, mean=0.8138s, min=0.00ms, median=0.9093s, max=1.4305s, stdev=0.5738s\n# [__main__:wait for ts] hits=6, total=5.6026s, mean=0.9338s, min=0.00ms, median=1.0672s, max=1.5336s, stdev=0.5914s\n# [__main__:wait for ts] hits=6, total=5.6026s, mean=0.9338s, min=0.00ms, median=1.0672s, max=1.5336s, stdev=0.5914s\n```\n\n```python\nimport time\nfrom stopwatch import profile\n\n@profile(\"wait for ts\", report_every=2)\ndef wait_for(ts):\n    if not ts:\n        return\n\n    time.sleep(ts[0])\n    wait_for(ts[1:])\n\nwait_for([0.1, 0.2, 0.3, 0.4, 0.5])\n# [__main__:wait for ts] hits=2, total=0.5034s, mean=0.2517s, min=0.02ms, median=0.2517s, max=0.5034s, stdev=0.3559s\n# [__main__:wait for ts] hits=4, total=2.6276s, mean=0.6569s, min=0.02ms, median=0.7065s, max=1.2146s, stdev=0.5260s\n# [__main__:wait for ts] hits=6, total=5.5693s, mean=0.9282s, min=0.02ms, median=1.0621s, max=1.5221s, stdev=0.5863s\n# [__main__:wait for ts] hits=6, total=5.5693s, mean=0.9282s, min=0.02ms, median=1.0621s, max=1.5221s, stdev=0.5863s\n```\n\n```python\nimport time\nfrom stopwatch import profile\n\n@profile(\"wait for ts\", report_every=None)\ndef wait_for(ts):\n    if not ts:\n        return\n\n    time.sleep(ts[0])\n    wait_for(ts[1:])\n\nwait_for([0.1, 0.2, 0.3, 0.4, 0.5])\n# [__main__:wait for ts] hits=6, total=5.5361s, mean=0.9227s, min=0.00ms, median=1.0554s, max=1.5145s, stdev=0.5827s\n```\n\n```python\nimport time\nfrom stopwatch import profile\n\n@profile(\n    \"wait for ts\",\n    format=\"<bold>[<blue>{module}</blue>:<green>{name}</green>]</bold> {statistics:hits, mean, median, stdev}\",\n)\ndef wait_for(ts):\n    if not ts:\n        return\n\n    time.sleep(ts[0])\n    wait_for(ts[1:])\n\nwait_for([0.1, 0.2, 0.3, 0.4, 0.5])\n# [__main__:wait for ts] hits=1, mean=0.01ms, median=0.01ms\n# [__main__:wait for ts] hits=2, mean=0.2527s, median=0.2527s, stdev=0.3573s\n# [__main__:wait for ts] hits=3, mean=0.4720s, median=0.5053s, stdev=0.4562s\n# [__main__:wait for ts] hits=4, mean=0.6579s, median=0.7079s, stdev=0.5263s\n# [__main__:wait for ts] hits=5, mean=0.8096s, median=0.9105s, stdev=0.5682s\n# [__main__:wait for ts] hits=6, mean=0.9282s, median=1.0631s, stdev=0.5854s\n# [__main__:wait for ts] hits=6, mean=0.9282s, median=1.0631s, stdev=0.5854s\n```\n\n```python\nimport time\nfrom stopwatch import stopwatch\n\nwith stopwatch():\n    for i in range(5):\n        time.sleep(i / 10)\n# [__main__:<module>:L5] ~ 1.0013s\n\n\nwith stopwatch(\"with message\"):\n    for i in range(5):\n        time.sleep(i / 10)\n# [__main__:<module>:L11] ~ 1.0013s - with message\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A simple stopwatch for measuring code performance",
    "version": "1.1.11",
    "project_urls": {
        "Homepage": "https://github.com/jonghwanhyeon/python-stopwatch"
    },
    "split_keywords": [
        "stopwatch",
        " profile"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "069ac54779d7c8e0cdae3571c7e4f4afa4c551b327fb051bc734d8eb08ee1529",
                "md5": "064bd5d9b0da82f3b23c4cbacc57198c",
                "sha256": "1d254d08712905e0c76edd2d742171f27ee70511c83a9b238b1d8b1d9fa5e9bf"
            },
            "downloads": -1,
            "filename": "python_stopwatch-1.1.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "064bd5d9b0da82f3b23c4cbacc57198c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 9052,
            "upload_time": "2024-07-14T06:33:39",
            "upload_time_iso_8601": "2024-07-14T06:33:39.122655Z",
            "url": "https://files.pythonhosted.org/packages/06/9a/c54779d7c8e0cdae3571c7e4f4afa4c551b327fb051bc734d8eb08ee1529/python_stopwatch-1.1.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7c3a68c18be11ad5a84599ae3318f9659a46cc93ebb0322257a17f8e50441880",
                "md5": "59e50bed2ae4794217d8021ad235806d",
                "sha256": "1a5f2de9dee1a5e27e415ded34aa6001bef20568601139bce9f06a358bb43df1"
            },
            "downloads": -1,
            "filename": "python_stopwatch-1.1.11.tar.gz",
            "has_sig": false,
            "md5_digest": "59e50bed2ae4794217d8021ad235806d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7076,
            "upload_time": "2024-07-14T06:33:40",
            "upload_time_iso_8601": "2024-07-14T06:33:40.575113Z",
            "url": "https://files.pythonhosted.org/packages/7c/3a/68c18be11ad5a84599ae3318f9659a46cc93ebb0322257a17f8e50441880/python_stopwatch-1.1.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-14 06:33:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jonghwanhyeon",
    "github_project": "python-stopwatch",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "python-stopwatch"
}
        
Elapsed time: 5.29755s