Name | timer4 JSON |
Version |
1.1.0
JSON |
| download |
home_page | |
Summary | Timing Python code made easy |
upload_time | 2023-04-01 18:39:17 |
maintainer | |
docs_url | None |
author | Binh Vu |
requires_python | >=3.7,<4.0 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# timer  
`timer` is a library to time your Python code.
## Installation
```bash
pip install timer4 # not timer
```
## Usage
- `timer` uses `with` statement to watch how long your code running:
```python
import time
from timer import Timer
with Timer().watch_and_report(msg='test'):
# running code that do lots of computation
time.sleep(1.0)
# when the code reach this part, it will output the message and the time it tooks.
# for example:
# test: 10.291 seconds
```
- If you don't want to report the result immediately, use the `watch` method instead. Whenever you've done, call `report`.
```python
import time
from timer import Timer
# you can either create a timer variable first, or use Timer.get_instance()
# that will return a singleton variable.
total = 0
for item in range(7):
# only measure the part that we want
with Timer.get_instance().watch("sum of square"):
total += item ** 2
time.sleep(0.2)
# doing other things that we don't want to measure
time.sleep(0.8)
Timer.get_instance().report()
```
- You can also use different way to print the message, such as using logging by passing a printing function to the report method: `report(print_fn=logger.info)`
- You can also choose to append the result to a file `report(append_to_file='/tmp/runtime.csv')`. This is useful if you want to measure runtime of your method and put it to a file to plot it later.
Raw data
{
"_id": null,
"home_page": "",
"name": "timer4",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "Binh Vu",
"author_email": "binh@toan2.com",
"download_url": "https://files.pythonhosted.org/packages/3c/22/ee963fdb5e0e69c7547cfc0e8d66810b0266d025ce82d3395d4362e65b3c/timer4-1.1.0.tar.gz",
"platform": null,
"description": "# timer  \n\n`timer` is a library to time your Python code.\n\n## Installation\n\n```bash\npip install timer4 # not timer\n```\n\n## Usage\n\n- `timer` uses `with` statement to watch how long your code running:\n\n```python\nimport time\nfrom timer import Timer\n\n\nwith Timer().watch_and_report(msg='test'):\n # running code that do lots of computation\n time.sleep(1.0)\n\n# when the code reach this part, it will output the message and the time it tooks.\n# for example:\n# test: 10.291 seconds\n```\n\n- If you don't want to report the result immediately, use the `watch` method instead. Whenever you've done, call `report`.\n\n```python\nimport time\nfrom timer import Timer\n\n# you can either create a timer variable first, or use Timer.get_instance()\n# that will return a singleton variable.\n\ntotal = 0\nfor item in range(7):\n # only measure the part that we want\n with Timer.get_instance().watch(\"sum of square\"):\n total += item ** 2\n time.sleep(0.2)\n\n # doing other things that we don't want to measure\n time.sleep(0.8)\n\nTimer.get_instance().report()\n```\n\n- You can also use different way to print the message, such as using logging by passing a printing function to the report method: `report(print_fn=logger.info)`\n\n- You can also choose to append the result to a file `report(append_to_file='/tmp/runtime.csv')`. This is useful if you want to measure runtime of your method and put it to a file to plot it later.\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Timing Python code made easy",
"version": "1.1.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1ab0cdd988729dcb76839b36aa970746361ce3e8a5e78ce552a2ffd20d9a05d3",
"md5": "71fedd6e7eb388bcafcad637ace003e1",
"sha256": "23d635ab721c04cc36b0a38333993bf057ebcb8067dd1b02c53d1c9b842f8ec8"
},
"downloads": -1,
"filename": "timer4-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "71fedd6e7eb388bcafcad637ace003e1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7,<4.0",
"size": 4448,
"upload_time": "2023-04-01T18:39:16",
"upload_time_iso_8601": "2023-04-01T18:39:16.168556Z",
"url": "https://files.pythonhosted.org/packages/1a/b0/cdd988729dcb76839b36aa970746361ce3e8a5e78ce552a2ffd20d9a05d3/timer4-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3c22ee963fdb5e0e69c7547cfc0e8d66810b0266d025ce82d3395d4362e65b3c",
"md5": "33933e7410b9b99f205744997c2eed9b",
"sha256": "4a93c16a3fec06ac9a3afce92a28ceb7dff514829e1ca6d8b4b3f8287b4b98ba"
},
"downloads": -1,
"filename": "timer4-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "33933e7410b9b99f205744997c2eed9b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7,<4.0",
"size": 3608,
"upload_time": "2023-04-01T18:39:17",
"upload_time_iso_8601": "2023-04-01T18:39:17.272536Z",
"url": "https://files.pythonhosted.org/packages/3c/22/ee963fdb5e0e69c7547cfc0e8d66810b0266d025ce82d3395d4362e65b3c/timer4-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-01 18:39:17",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "timer4"
}