# tm_profiler
### Python - time profiler
> Package version >= 3.0.1 supported from Python >= 3.8 .<br>For Python 2, please use package version 2.x.x.
Developed by Normunds Pureklis (c) 2025
### Installation
Install via pip::
$ pip install tm-profiler
## Available functions
> Imported like: `import tm_profiler` or `import tm_profiler as tp`
| Function | Usage |
|--------------------------------------------|------------------------------------------|
| profile(print_inline=False) | Decorator for function time profilig |
| print_stat(sort_by: TpSort = TpSort.NAME) | Print all collected statistic |
| print_last() | Print statistic last collected record |
| disable() | Disable profiler |
| enable() | Enable profiler |
| reset() | Reset profiler |
| set_output_dec(int) | Set profiler output decimal places |
| set_name_format(name_format: TpNameFormat) | Set profiler output function name format |
---
> Imported like: `from tm_profiler import *`
| Function | Usage |
|-----------------------------------------------|------------------------------------------|
| tp_profile(print_inline=False) | Decorator for function time profilig |
| tp_print_stat(sort_by: TpSort = TpSort.NAME) | Print all collected statistic |
| tp_print_last() | Print statistic last collected record |
| tp_disable() | Disable profiler |
| tp_enable() | Enable profiler |
| tp_reset() | Reset profiler |
| tp_set_output_dec(int) | Set profiler output decimal places |
| tp_set_name_format(name_format: TpNameFormat) | Set profiler output function name format |
## Usage
#### Add decorator to functions which needs to profile.<br>Run `print_stat()` function to print time statistic.
```python
import tm_profiler as tp
@tp.profile()
def func_a():
res = 0
for _ in range(1000000):
res = 100 / 10
return res
@tp.profile()
def func_b():
res = 0
for _ in range(1000000):
res = 100 / 10
return res
func_a()
for _ in range(3):
func_b()
tp.print_stat()
```
Output:
-------------------------------------------------------------
## Time Profiler: #
-------------------------------------------------------------
| Name | Time total(s) | Calls | Time average(s) |
-------------------------------------------------------------
| main.py[func_a] | 0.0117 | 1 | 0.0117 |
| main.py[func_b] | 0.0317 | 3 | 0.0106 |
-------------------------------------------------------------
---
#### To print inline time statistic, use decorator function argument `print_inline=True`.
```python
import tm_profiler as tp
@tp.profile(print_inline=True)
def func_a():
res = 0
for _ in range(1000000):
res = 100 / 10
return res
func_a()
```
Output:
> NOTE: Profiler information will be printed before function result is returned!
## TP # Function (main.py[func_a]:1) - took: 0.0105s #
Function result: 10.0
---
#### To print time statistic for last function run, use profiler function `print_last()`.
```python
import tm_profiler as tp
@tp.profile()
def func_a():
res = 0
for _ in range(1000000):
res = 100 / 10
return res
print(f"Function result: {func_a()}")
tp.print_last()
```
Output:
Function result: 10.0
## TP # Function (main.py[func_a]:1) - took: 0.0146s #
---
#### To disable profiler, use profiler function `disable()`.<br>Statistic will not be collected and printed.<br>To enable back use function `enable()`.
```python
import tm_profiler as tp
@tp.profile()
def func_a():
res = 0
for _ in range(1000000):
res = 100 / 10
return res
tp.disable()
print(f"Function result1: {func_a()}")
tp.print_last()
tp.enable()
print(f"Function result2: {func_a()}")
tp.print_last()
```
Output:
Function result1: 10.0
Function result2: 10.0
## TP # Function (main.py[func_a]:1) - took: 0.0123s #
---
#### Use `reset()` function to reset profiler collected data.
```python
import tm_profiler as tp
@tp.profile()
def func_a():
res = 0
for _ in range(1000000):
res = 100 / 10
return res
@tp.profile()
def func_b():
res = 0
for _ in range(1000000):
res = 100 / 10
return res
func_a()
for _ in range(3):
func_b()
tp.print_stat()
tp.reset()
tp.print_stat()
func_a()
tp.print_stat()
```
Output:
-------------------------------------------------------------
## Time Profiler: #
-------------------------------------------------------------
| Name | Time total(s) | Calls | Time average(s) |
-------------------------------------------------------------
| main.py[func_a] | 0.0117 | 1 | 0.0117 |
| main.py[func_b] | 0.0317 | 3 | 0.0106 |
-------------------------------------------------------------
--------------------------------------------------
## Time Profiler: #
--------------------------------------------------
| Name | Time total(s) | Calls | Time average(s) |
--------------------------------------------------
--------------------------------------------------
-------------------------------------------------------------
## Time Profiler: #
-------------------------------------------------------------
| Name | Time total(s) | Calls | Time average(s) |
-------------------------------------------------------------
| main.py[func_a] | 0.0108 | 1 | 0.0108 |
-------------------------------------------------------------
---
#### Use `set_output_dec(int)` to configure output number decimal places (affects only print output).
```python
import tm_profiler as tp
@tp.profile()
def func_a():
return 10
func_a()
tp.set_output_dec(6)
tp.print_last()
```
Output:
## TP # Function (main.py[func_a]:1) - took: 0.014630s #
---
#### Use `set_name_format(name_format: TpNameFormat)` to configure how is stored decorated function name<br>(Imortant to set before any decorated function is used, as it affects how function name is stored).
```python
import tm_profiler as tp
tp.set_name_format(name_format=tp.TpNameFormat.REL)
# Available options:
# TpNameFormat.NAME - function name (default)
# TpNameFormat.REL - function name with relative path
# TpNameFormat.ABS - function name with absolute path
@tp.profile()
def func_a():
return 10
func_a()
tp.set_output_dec(6)
tp.print_last()
```
---
#### Sort profiler output data.<br>Use `sort_by` parameter for function `print_stat()` to sort output.
```python
import tm_profiler as tp
@tp.profile()
def func_a():
return 10
func_a()
tp.print_stat(sort_by=tp.TpSort.CALLS)
# Available options:
# TpSort.NAME - sort by name (default)
# TpSort.CALLS - sort by count of calls
# TpSort.TOTAL - sort by total time
# TpSort.AVG - sort by average time
```
Raw data
{
"_id": null,
"home_page": null,
"name": "tm-profiler",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "python, profiler, time, time profiler",
"author": "NorchaHack (Normunds Pureklis)",
"author_email": "<norchahack@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/b4/3f/2fee5203d7d1b7e4af372bdf02951e7aae114a487cfd0b55a123237b7d7b/tm_profiler-3.0.1.tar.gz",
"platform": null,
"description": "\n# tm_profiler\n### Python - time profiler\n\n> Package version >= 3.0.1 supported from Python >= 3.8 .<br>For Python 2, please use package version 2.x.x.\n\n Developed by Normunds Pureklis (c) 2025\n\n### Installation\n\nInstall via pip::\n\n $ pip install tm-profiler\n\n## Available functions\n> Imported like: `import tm_profiler` or `import tm_profiler as tp`\n\n| Function | Usage |\n|--------------------------------------------|------------------------------------------|\n| profile(print_inline=False) | Decorator for function time profilig |\n| print_stat(sort_by: TpSort = TpSort.NAME) | Print all collected statistic |\n| print_last() | Print statistic last collected record |\n| disable() | Disable profiler | \n| enable() | Enable profiler | \n| reset() | Reset profiler |\n| set_output_dec(int) | Set profiler output decimal places |\n| set_name_format(name_format: TpNameFormat) | Set profiler output function name format |\n\n---\n> Imported like: `from tm_profiler import *`\n\n| Function | Usage |\n|-----------------------------------------------|------------------------------------------|\n| tp_profile(print_inline=False) | Decorator for function time profilig |\n| tp_print_stat(sort_by: TpSort = TpSort.NAME) | Print all collected statistic |\n| tp_print_last() | Print statistic last collected record |\n| tp_disable() | Disable profiler | \n| tp_enable() | Enable profiler | \n| tp_reset() | Reset profiler |\n| tp_set_output_dec(int) | Set profiler output decimal places |\n| tp_set_name_format(name_format: TpNameFormat) | Set profiler output function name format |\n\n## Usage\n\n#### Add decorator to functions which needs to profile.<br>Run `print_stat()` function to print time statistic.\n\n```python\nimport tm_profiler as tp\n\n@tp.profile()\ndef func_a():\n res = 0\n for _ in range(1000000):\n res = 100 / 10\n return res\n\n@tp.profile()\ndef func_b():\n res = 0\n for _ in range(1000000):\n res = 100 / 10\n return res\n\nfunc_a()\n\nfor _ in range(3):\n func_b()\n\ntp.print_stat()\n```\nOutput:\n\n -------------------------------------------------------------\n ## Time Profiler: #\n -------------------------------------------------------------\n | Name | Time total(s) | Calls | Time average(s) |\n -------------------------------------------------------------\n | main.py[func_a] | 0.0117 | 1 | 0.0117 |\n | main.py[func_b] | 0.0317 | 3 | 0.0106 |\n -------------------------------------------------------------\n\n---\n#### To print inline time statistic, use decorator function argument `print_inline=True`.\n\n```python\nimport tm_profiler as tp\n\n@tp.profile(print_inline=True)\ndef func_a():\n res = 0\n for _ in range(1000000):\n res = 100 / 10\n return res\n\nfunc_a()\n```\nOutput:\n> NOTE: Profiler information will be printed before function result is returned!\n\n ## TP # Function (main.py[func_a]:1) - took: 0.0105s #\n Function result: 10.0\n\n---\n#### To print time statistic for last function run, use profiler function `print_last()`.\n\n```python\nimport tm_profiler as tp\n\n@tp.profile()\ndef func_a():\n res = 0\n for _ in range(1000000):\n res = 100 / 10\n return res\n\nprint(f\"Function result: {func_a()}\")\n\ntp.print_last()\n```\nOutput:\n\n Function result: 10.0\n ## TP # Function (main.py[func_a]:1) - took: 0.0146s #\n\n---\n#### To disable profiler, use profiler function `disable()`.<br>Statistic will not be collected and printed.<br>To enable back use function `enable()`.\n\n```python\nimport tm_profiler as tp\n\n@tp.profile()\ndef func_a():\n res = 0\n for _ in range(1000000):\n res = 100 / 10\n return res\n\ntp.disable()\nprint(f\"Function result1: {func_a()}\")\ntp.print_last()\n\ntp.enable()\nprint(f\"Function result2: {func_a()}\")\ntp.print_last()\n```\nOutput:\n\n Function result1: 10.0\n Function result2: 10.0\n ## TP # Function (main.py[func_a]:1) - took: 0.0123s #\n\n---\n#### Use `reset()` function to reset profiler collected data.\n\n```python\nimport tm_profiler as tp\n\n@tp.profile()\ndef func_a():\n res = 0\n for _ in range(1000000):\n res = 100 / 10\n return res\n\n@tp.profile()\ndef func_b():\n res = 0\n for _ in range(1000000):\n res = 100 / 10\n return res\n\nfunc_a()\n\nfor _ in range(3):\n func_b()\n\ntp.print_stat()\n\ntp.reset()\ntp.print_stat()\n\nfunc_a()\ntp.print_stat()\n```\nOutput:\n\n -------------------------------------------------------------\n ## Time Profiler: #\n -------------------------------------------------------------\n | Name | Time total(s) | Calls | Time average(s) |\n -------------------------------------------------------------\n | main.py[func_a] | 0.0117 | 1 | 0.0117 |\n | main.py[func_b] | 0.0317 | 3 | 0.0106 |\n -------------------------------------------------------------\n --------------------------------------------------\n ## Time Profiler: #\n --------------------------------------------------\n | Name | Time total(s) | Calls | Time average(s) |\n --------------------------------------------------\n --------------------------------------------------\n -------------------------------------------------------------\n ## Time Profiler: #\n -------------------------------------------------------------\n | Name | Time total(s) | Calls | Time average(s) |\n -------------------------------------------------------------\n | main.py[func_a] | 0.0108 | 1 | 0.0108 |\n -------------------------------------------------------------\n\n---\n#### Use `set_output_dec(int)` to configure output number decimal places (affects only print output).\n\n```python\nimport tm_profiler as tp\n\n@tp.profile()\ndef func_a():\n return 10\n\nfunc_a()\n\ntp.set_output_dec(6)\ntp.print_last()\n```\nOutput:\n\n ## TP # Function (main.py[func_a]:1) - took: 0.014630s #\n\n---\n#### Use `set_name_format(name_format: TpNameFormat)` to configure how is stored decorated function name<br>(Imortant to set before any decorated function is used, as it affects how function name is stored).\n\n```python\nimport tm_profiler as tp\n\ntp.set_name_format(name_format=tp.TpNameFormat.REL)\n# Available options:\n# TpNameFormat.NAME - function name (default)\n# TpNameFormat.REL - function name with relative path\n# TpNameFormat.ABS - function name with absolute path\n\n@tp.profile()\ndef func_a():\n return 10\n\nfunc_a()\n\ntp.set_output_dec(6)\ntp.print_last()\n```\n\n---\n#### Sort profiler output data.<br>Use `sort_by` parameter for function `print_stat()` to sort output.\n\n```python\nimport tm_profiler as tp\n\n@tp.profile()\ndef func_a():\n return 10\n\nfunc_a()\n\ntp.print_stat(sort_by=tp.TpSort.CALLS)\n# Available options:\n# TpSort.NAME - sort by name (default)\n# TpSort.CALLS - sort by count of calls\n# TpSort.TOTAL - sort by total time\n# TpSort.AVG - sort by average time\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Time profiler",
"version": "3.0.1",
"project_urls": null,
"split_keywords": [
"python",
" profiler",
" time",
" time profiler"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "9de8691260bfc19f34068a29554e449c7f88a43346d6c301e2aff131b2b1f641",
"md5": "1f280f63948f445327e1ff02982742da",
"sha256": "5cb716f31cf23b5cd96147e47fb6fe6661d26c1f7736a2e22df9241d8949da08"
},
"downloads": -1,
"filename": "tm_profiler-3.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1f280f63948f445327e1ff02982742da",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 6528,
"upload_time": "2025-09-10T18:54:49",
"upload_time_iso_8601": "2025-09-10T18:54:49.367354Z",
"url": "https://files.pythonhosted.org/packages/9d/e8/691260bfc19f34068a29554e449c7f88a43346d6c301e2aff131b2b1f641/tm_profiler-3.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "b43f2fee5203d7d1b7e4af372bdf02951e7aae114a487cfd0b55a123237b7d7b",
"md5": "7674372cd11ea0304574d4b8a38e9d41",
"sha256": "0bf8aaf2a59f17b9419a2a13a2b4bc86089467ac88d33c55fe8776b192cfd48b"
},
"downloads": -1,
"filename": "tm_profiler-3.0.1.tar.gz",
"has_sig": false,
"md5_digest": "7674372cd11ea0304574d4b8a38e9d41",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 9679,
"upload_time": "2025-09-10T18:54:50",
"upload_time_iso_8601": "2025-09-10T18:54:50.113431Z",
"url": "https://files.pythonhosted.org/packages/b4/3f/2fee5203d7d1b7e4af372bdf02951e7aae114a487cfd0b55a123237b7d7b/tm_profiler-3.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-10 18:54:50",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "tm-profiler"
}