timer-for-python 0.7.18__tar.gz → 0.9.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {timer-for-python-0.7.18/src/timer_for_python.egg-info → timer_for_python-0.9.0}/PKG-INFO +19 -16
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/README.md +13 -10
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/pyproject.toml +1 -1
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/setup.cfg +7 -7
- timer_for_python-0.9.0/src/timer/__init__.py +5 -0
- timer_for_python-0.9.0/src/timer/decorator/__init__.py +1 -0
- timer_for_python-0.9.0/src/timer/decorator/function.py +64 -0
- timer_for_python-0.9.0/src/timer/helper/output.py +34 -0
- timer_for_python-0.9.0/src/timer/model/abc/mkdocstrings.py +10 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/model/timer.py +14 -20
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/version.py +1 -1
- {timer-for-python-0.7.18 → timer_for_python-0.9.0/src/timer_for_python.egg-info}/PKG-INFO +19 -16
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer_for_python.egg-info/SOURCES.txt +3 -1
- timer_for_python-0.9.0/src/timer_for_python.egg-info/requires.txt +10 -0
- timer-for-python-0.7.18/src/timer/__init__.py +0 -5
- timer-for-python-0.7.18/src/timer/decorator/benchmark.py +0 -14
- timer-for-python-0.7.18/src/timer/helper/output.py +0 -33
- timer-for-python-0.7.18/src/timer_for_python.egg-info/requires.txt +0 -10
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/LICENSE.md +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/MANIFEST.in +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/constant/__init__.py +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/constant/decimals.py +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/constant/various.py +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/controller/__init__.py +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/error/__init__.py +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/helper/__init__.py +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/helper/decimals.py +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/helper/thread/__init__.py +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/helper/thread/list.py +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/helper/time_fractions.py +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/model/__init__.py +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/model/elapsed_time_fractions.py +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/model/thread_item.py +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/model/time_fractions.py +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/model/timer_base.py +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/py.typed +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer_for_python.egg-info/dependency_links.txt +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer_for_python.egg-info/not-zip-safe +0 -0
- {timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer_for_python.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: timer-for-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.0
|
|
4
4
|
Summary: Timer for Python
|
|
5
5
|
Home-page: https://jakob-bagterp.github.io/timer-for-python/
|
|
6
6
|
Download-URL: https://pypi.org/project/timer-for-python/
|
|
@@ -25,21 +25,21 @@ Classifier: Operating System :: OS Independent
|
|
|
25
25
|
Requires-Python: >=3.10
|
|
26
26
|
Description-Content-Type: text/markdown
|
|
27
27
|
License-File: LICENSE.md
|
|
28
|
-
Requires-Dist: colorist==1.8.
|
|
28
|
+
Requires-Dist: colorist==1.8.3
|
|
29
29
|
Provides-Extra: testing
|
|
30
|
-
Requires-Dist: coverage==7.6.
|
|
30
|
+
Requires-Dist: coverage==7.6.8; extra == "testing"
|
|
31
31
|
Requires-Dist: flake8==7.1.1; extra == "testing"
|
|
32
32
|
Requires-Dist: mypy==1.13.0; extra == "testing"
|
|
33
|
-
Requires-Dist: numpy==2.1.
|
|
34
|
-
Requires-Dist: pytest==8.3.
|
|
35
|
-
Requires-Dist: pytest-cov==
|
|
33
|
+
Requires-Dist: numpy==2.1.3; extra == "testing"
|
|
34
|
+
Requires-Dist: pytest==8.3.4; extra == "testing"
|
|
35
|
+
Requires-Dist: pytest-cov==6.0.0; extra == "testing"
|
|
36
36
|
Requires-Dist: tox==4.23.2; extra == "testing"
|
|
37
37
|
|
|
38
|
-
[](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
|
|
39
39
|
[](https://www.python.org)
|
|
40
40
|
[](https://github.com/jakob-bagterp/timer-for-python/blob/master/LICENSE.md)
|
|
41
41
|
[](https://codecov.io/gh/jakob-bagterp/timer-for-python)
|
|
42
|
-
[](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/github-code-scanning/codeql)
|
|
43
43
|
[](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/test.yml)
|
|
44
44
|
[](https://pepy.tech/project/timer-for-python)
|
|
45
45
|
|
|
@@ -74,12 +74,12 @@ with Timer():
|
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
#### Decorator
|
|
77
|
-
Or use the `
|
|
77
|
+
Or use the `function_timer` as a function decorator:
|
|
78
78
|
|
|
79
79
|
```python
|
|
80
|
-
from timer import
|
|
80
|
+
from timer import function_timer
|
|
81
81
|
|
|
82
|
-
@
|
|
82
|
+
@function_timer()
|
|
83
83
|
def test_function():
|
|
84
84
|
# Insert your code here
|
|
85
85
|
|
|
@@ -90,7 +90,7 @@ test_function()
|
|
|
90
90
|
|
|
91
91
|
### Core Features
|
|
92
92
|
#### Decimals
|
|
93
|
-
Instead of the default value of `2` for `decimals``, you can set the output precision up to `9` in the `decimals`
|
|
93
|
+
Instead of the default value of `2` for `decimals``, you can set the output precision up to `9` in the `decimals` parameter:
|
|
94
94
|
|
|
95
95
|
```python
|
|
96
96
|
timer = Timer()
|
|
@@ -104,7 +104,7 @@ timer.stop() # Output example: 0.12345 seconds
|
|
|
104
104
|
#### Multiple Threads
|
|
105
105
|
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.
|
|
106
106
|
|
|
107
|
-
To measure the performance of multiple blocks of code, use the `thread`
|
|
107
|
+
To measure the performance of multiple blocks of code, use the `thread` parameter to name different threads:
|
|
108
108
|
|
|
109
109
|
```python
|
|
110
110
|
timer = Timer()
|
|
@@ -138,9 +138,12 @@ with Timer(thread="A")
|
|
|
138
138
|
# Output example: 6.78 seconds for thread A
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
## Become a Sponsor 🏅
|
|
142
|
+
If you find this project helpful, please consider supporting its development. Your donations will help keep it alive and growing. Every contribution, no matter the size, makes a difference.
|
|
143
|
+
|
|
144
|
+
[Donate on GitHub Sponsors](https://github.com/sponsors/jakob-bagterp)
|
|
145
|
+
|
|
146
|
+
Thank you for your support! 🙌
|
|
144
147
|
|
|
145
148
|
## Contribute
|
|
146
149
|
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).
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
[](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
|
|
2
2
|
[](https://www.python.org)
|
|
3
3
|
[](https://github.com/jakob-bagterp/timer-for-python/blob/master/LICENSE.md)
|
|
4
4
|
[](https://codecov.io/gh/jakob-bagterp/timer-for-python)
|
|
5
|
-
[](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/github-code-scanning/codeql)
|
|
6
6
|
[](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/test.yml)
|
|
7
7
|
[](https://pepy.tech/project/timer-for-python)
|
|
8
8
|
|
|
@@ -37,12 +37,12 @@ with Timer():
|
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
#### Decorator
|
|
40
|
-
Or use the `
|
|
40
|
+
Or use the `function_timer` as a function decorator:
|
|
41
41
|
|
|
42
42
|
```python
|
|
43
|
-
from timer import
|
|
43
|
+
from timer import function_timer
|
|
44
44
|
|
|
45
|
-
@
|
|
45
|
+
@function_timer()
|
|
46
46
|
def test_function():
|
|
47
47
|
# Insert your code here
|
|
48
48
|
|
|
@@ -53,7 +53,7 @@ test_function()
|
|
|
53
53
|
|
|
54
54
|
### Core Features
|
|
55
55
|
#### Decimals
|
|
56
|
-
Instead of the default value of `2` for `decimals``, you can set the output precision up to `9` in the `decimals`
|
|
56
|
+
Instead of the default value of `2` for `decimals``, you can set the output precision up to `9` in the `decimals` parameter:
|
|
57
57
|
|
|
58
58
|
```python
|
|
59
59
|
timer = Timer()
|
|
@@ -67,7 +67,7 @@ timer.stop() # Output example: 0.12345 seconds
|
|
|
67
67
|
#### Multiple Threads
|
|
68
68
|
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.
|
|
69
69
|
|
|
70
|
-
To measure the performance of multiple blocks of code, use the `thread`
|
|
70
|
+
To measure the performance of multiple blocks of code, use the `thread` parameter to name different threads:
|
|
71
71
|
|
|
72
72
|
```python
|
|
73
73
|
timer = Timer()
|
|
@@ -101,9 +101,12 @@ with Timer(thread="A")
|
|
|
101
101
|
# Output example: 6.78 seconds for thread A
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
## Become a Sponsor 🏅
|
|
105
|
+
If you find this project helpful, please consider supporting its development. Your donations will help keep it alive and growing. Every contribution, no matter the size, makes a difference.
|
|
106
|
+
|
|
107
|
+
[Donate on GitHub Sponsors](https://github.com/sponsors/jakob-bagterp)
|
|
108
|
+
|
|
109
|
+
Thank you for your support! 🙌
|
|
107
110
|
|
|
108
111
|
## Contribute
|
|
109
112
|
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).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = timer-for-python
|
|
3
|
-
version = 0.
|
|
3
|
+
version = 0.9.0
|
|
4
4
|
author = Jakob Bagterp
|
|
5
5
|
author_email = jakob_bagterp@hotmail.com
|
|
6
6
|
maintainer = Jakob Bagterp
|
|
@@ -36,20 +36,20 @@ package_dir =
|
|
|
36
36
|
packages = find:
|
|
37
37
|
python_requires = >=3.10
|
|
38
38
|
setup_requires =
|
|
39
|
-
colorist==1.8.
|
|
39
|
+
colorist==1.8.3
|
|
40
40
|
install_requires =
|
|
41
|
-
colorist==1.8.
|
|
41
|
+
colorist==1.8.3
|
|
42
42
|
zip_safe = no
|
|
43
43
|
include_package_data = True
|
|
44
44
|
|
|
45
45
|
[options.extras_require]
|
|
46
46
|
testing =
|
|
47
|
-
coverage==7.6.
|
|
47
|
+
coverage==7.6.8
|
|
48
48
|
flake8==7.1.1
|
|
49
49
|
mypy==1.13.0
|
|
50
|
-
numpy==2.1.
|
|
51
|
-
pytest==8.3.
|
|
52
|
-
pytest-cov==
|
|
50
|
+
numpy==2.1.3
|
|
51
|
+
pytest==8.3.4
|
|
52
|
+
pytest-cov==6.0.0
|
|
53
53
|
tox==4.23.2
|
|
54
54
|
|
|
55
55
|
[options.packages.find]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__all__: list[str] = []
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
from collections.abc import Callable
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from ..model.abc.mkdocstrings import MkDocstringsWrapper_ABC
|
|
6
|
+
from ..model.timer import Timer
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def function_timer(thread: str | None = None, decimals: int = 2) -> Callable[..., Any]:
|
|
10
|
+
"""Function decorator to measure the performance of a function."""
|
|
11
|
+
|
|
12
|
+
def decorator(function: Callable[..., Any]) -> Callable[..., Any]:
|
|
13
|
+
@functools.wraps(function)
|
|
14
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
15
|
+
thread_name = thread if thread else function.__name__
|
|
16
|
+
with Timer(thread=thread_name, decimals=decimals):
|
|
17
|
+
return function(*args, **kwargs)
|
|
18
|
+
return wrapper
|
|
19
|
+
return decorator
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class MkDocstringsWrapper(MkDocstringsWrapper_ABC):
|
|
23
|
+
def function_timer(self, thread: str | None = None, decimals: int = 2) -> Callable[..., Any]:
|
|
24
|
+
"""Function decorator to measure the performance of a function.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
thread (str | None, optional): Option to start new thread. By default, the thread name is the function name.
|
|
28
|
+
decimals (int | None, optional): Option to define decimals for output. Minimum `0` (for no decimals) and maximum `9`. If `None`, default is `2` decimals. May be overruled in certain cases due to [humanised output](../user-guide/humanised-output.md).
|
|
29
|
+
|
|
30
|
+
Example:
|
|
31
|
+
Basic usage:
|
|
32
|
+
|
|
33
|
+
```python linenums="1" hl_lines="3"
|
|
34
|
+
from timer import function_timer
|
|
35
|
+
|
|
36
|
+
@function_timer()
|
|
37
|
+
def test_function():
|
|
38
|
+
# Insert your code here
|
|
39
|
+
|
|
40
|
+
test_function()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
How it appears in the terminal:
|
|
44
|
+
|
|
45
|
+
<pre><code>% Elapsed time: 12.34 seconds for thread <span class="fg-green">TEST_FUNCTION</span></code></pre>
|
|
46
|
+
|
|
47
|
+
With custom thread name and decimals:
|
|
48
|
+
|
|
49
|
+
```python linenums="1" hl_lines="3"
|
|
50
|
+
from timer import function_timer
|
|
51
|
+
|
|
52
|
+
@function_timer(thread="custom", decimals=5)
|
|
53
|
+
def test_function():
|
|
54
|
+
# Insert your code here
|
|
55
|
+
|
|
56
|
+
test_function()
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
How it appears in the terminal:
|
|
60
|
+
|
|
61
|
+
<pre><code>% Elapsed time: 0.12345 seconds for thread <span class="fg-green">CUSTOM</span></code></pre>
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
return function_timer(thread=thread, decimals=decimals)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from colorist import Color
|
|
2
|
+
|
|
3
|
+
from .. import error, helper
|
|
4
|
+
from ..model.time_fractions import TimeFractions
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def message(thread: str, fractions: TimeFractions, decimals: int) -> None:
|
|
8
|
+
try:
|
|
9
|
+
intro = "Elapsed time:"
|
|
10
|
+
thread_info = "" if helper.thread.is_none(thread) else f" for thread {Color.GREEN}{thread}{Color.OFF}"
|
|
11
|
+
time = fractions.time
|
|
12
|
+
if time.days > 0:
|
|
13
|
+
# Format: 1d 2h 3m 4s
|
|
14
|
+
print(f"{intro} {time.days}d {time.hours}h {time.minutes}m {fractions.seconds_rounded()}s{thread_info}")
|
|
15
|
+
elif time.hours > 0:
|
|
16
|
+
# Format: 1h 2m 3s
|
|
17
|
+
print(f"{intro} {time.hours}h {time.minutes}m {fractions.seconds_rounded()}s{thread_info}")
|
|
18
|
+
elif time.minutes > 0:
|
|
19
|
+
# Format: 62.34 seconds (1m 2s)
|
|
20
|
+
print(f"{intro} {fractions.count_minutes_to_seconds():.{decimals}f} seconds ({time.minutes}m {fractions.seconds_rounded()}s){thread_info}")
|
|
21
|
+
elif time.seconds > 0:
|
|
22
|
+
# Format: 0.123456789 seconds
|
|
23
|
+
print(f"{intro} {fractions.count_seconds_to_float():.{decimals}f} seconds{thread_info}")
|
|
24
|
+
elif time.milliseconds > 0:
|
|
25
|
+
# Format: 123.45 milliseconds
|
|
26
|
+
print(f"{intro} {fractions.count_milliseconds_to_float():.{decimals}f} milliseconds{thread_info}")
|
|
27
|
+
elif time.microseconds > 0:
|
|
28
|
+
# Format: 234.56 microseconds
|
|
29
|
+
print(f"{intro} {fractions.count_microseconds_to_float():.{decimals}f} microseconds{thread_info}")
|
|
30
|
+
else:
|
|
31
|
+
# Format: 345 nanoseconds
|
|
32
|
+
print(f"{intro} {time.nanoseconds} nanoseconds{thread_info}")
|
|
33
|
+
except Exception:
|
|
34
|
+
error.message_for_action("in the Timer's output message module", thread)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from abc import ABC
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class MkDocstringsWrapper_ABC(ABC):
|
|
5
|
+
"""Abstract base class used to documentation standalone functions now that MkDocstrings (as far as I know) only support reference of functions within classes.
|
|
6
|
+
|
|
7
|
+
Should not used for other purposes than documentation."""
|
|
8
|
+
|
|
9
|
+
def __init__(self) -> None:
|
|
10
|
+
pass # pragma: no cover
|
|
@@ -62,12 +62,12 @@ class Timer(TimerBase):
|
|
|
62
62
|
```python linenums="1" hl_lines="3"
|
|
63
63
|
from timer import Timer
|
|
64
64
|
|
|
65
|
-
timer = Timer(thread="
|
|
65
|
+
timer = Timer(thread="custom", decimals=5)
|
|
66
66
|
timer.start()
|
|
67
67
|
|
|
68
68
|
# Insert your code here
|
|
69
69
|
|
|
70
|
-
timer.stop(thread="
|
|
70
|
+
timer.stop(thread="custom")
|
|
71
71
|
```
|
|
72
72
|
|
|
73
73
|
Or with a `with` statement as [context manager](../user-guide/context-manager.md):
|
|
@@ -75,15 +75,13 @@ class Timer(TimerBase):
|
|
|
75
75
|
```python linenums="1" hl_lines="3"
|
|
76
76
|
from timer import Timer
|
|
77
77
|
|
|
78
|
-
with Timer(thread="
|
|
78
|
+
with Timer(thread="custom", decimals=5):
|
|
79
79
|
# Insert your code here
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
As before, the terminal will output the same result in both cases:
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
Elapsed time: 0.12345 seconds for thread MY_THREAD
|
|
86
|
-
```
|
|
84
|
+
<pre><code>% Elapsed time: 0.12345 seconds for thread <span class="fg-green">CUSTOM</span></code></pre>
|
|
87
85
|
"""
|
|
88
86
|
|
|
89
87
|
if not self._lock_init: # Ensure that initialisation of the lists only runs the first time.
|
|
@@ -125,7 +123,7 @@ class Timer(TimerBase):
|
|
|
125
123
|
timer.stop()
|
|
126
124
|
```
|
|
127
125
|
|
|
128
|
-
|
|
126
|
+
How it appears in the terminal:
|
|
129
127
|
|
|
130
128
|
```text title=""
|
|
131
129
|
Elapsed time: 12.34 seconds
|
|
@@ -137,18 +135,16 @@ class Timer(TimerBase):
|
|
|
137
135
|
from timer import Timer
|
|
138
136
|
|
|
139
137
|
timer = Timer()
|
|
140
|
-
timer.start(thread="
|
|
138
|
+
timer.start(thread="custom", decimals=5)
|
|
141
139
|
|
|
142
140
|
# Insert your code here
|
|
143
141
|
|
|
144
|
-
timer.stop(thread="
|
|
142
|
+
timer.stop(thread="custom")
|
|
145
143
|
```
|
|
146
144
|
|
|
147
|
-
|
|
145
|
+
How it appears in the terminal:
|
|
148
146
|
|
|
149
|
-
|
|
150
|
-
Elapsed time: 0.12345 seconds for thread MY_THREAD
|
|
151
|
-
```
|
|
147
|
+
<pre><code>% Elapsed time: 0.12345 seconds for thread <span class="fg-green">CUSTOM</span></code></pre>
|
|
152
148
|
"""
|
|
153
149
|
|
|
154
150
|
try:
|
|
@@ -177,7 +173,7 @@ class Timer(TimerBase):
|
|
|
177
173
|
timer.stop()
|
|
178
174
|
```
|
|
179
175
|
|
|
180
|
-
|
|
176
|
+
How it appears in the terminal:
|
|
181
177
|
|
|
182
178
|
```text title=""
|
|
183
179
|
Elapsed time: 12.34 seconds
|
|
@@ -189,18 +185,16 @@ class Timer(TimerBase):
|
|
|
189
185
|
from timer import Timer
|
|
190
186
|
|
|
191
187
|
timer = Timer()
|
|
192
|
-
timer.start(thread="
|
|
188
|
+
timer.start(thread="custom", decimals=5)
|
|
193
189
|
|
|
194
190
|
# Insert your code here
|
|
195
191
|
|
|
196
|
-
timer.stop(thread="
|
|
192
|
+
timer.stop(thread="custom")
|
|
197
193
|
```
|
|
198
194
|
|
|
199
|
-
|
|
195
|
+
How it appears in the terminal:
|
|
200
196
|
|
|
201
|
-
|
|
202
|
-
Elapsed time: 0.12345 seconds for thread MY_THREAD
|
|
203
|
-
```
|
|
197
|
+
<pre><code>% Elapsed time: 0.12345 seconds for thread <span class="fg-green">CUSTOM</span></code></pre>
|
|
204
198
|
"""
|
|
205
199
|
|
|
206
200
|
try:
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version_info__ = (0,
|
|
1
|
+
__version_info__ = (0, 9, 0)
|
|
2
2
|
__version__ = ".".join(map(str, __version_info__))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: timer-for-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.0
|
|
4
4
|
Summary: Timer for Python
|
|
5
5
|
Home-page: https://jakob-bagterp.github.io/timer-for-python/
|
|
6
6
|
Download-URL: https://pypi.org/project/timer-for-python/
|
|
@@ -25,21 +25,21 @@ Classifier: Operating System :: OS Independent
|
|
|
25
25
|
Requires-Python: >=3.10
|
|
26
26
|
Description-Content-Type: text/markdown
|
|
27
27
|
License-File: LICENSE.md
|
|
28
|
-
Requires-Dist: colorist==1.8.
|
|
28
|
+
Requires-Dist: colorist==1.8.3
|
|
29
29
|
Provides-Extra: testing
|
|
30
|
-
Requires-Dist: coverage==7.6.
|
|
30
|
+
Requires-Dist: coverage==7.6.8; extra == "testing"
|
|
31
31
|
Requires-Dist: flake8==7.1.1; extra == "testing"
|
|
32
32
|
Requires-Dist: mypy==1.13.0; extra == "testing"
|
|
33
|
-
Requires-Dist: numpy==2.1.
|
|
34
|
-
Requires-Dist: pytest==8.3.
|
|
35
|
-
Requires-Dist: pytest-cov==
|
|
33
|
+
Requires-Dist: numpy==2.1.3; extra == "testing"
|
|
34
|
+
Requires-Dist: pytest==8.3.4; extra == "testing"
|
|
35
|
+
Requires-Dist: pytest-cov==6.0.0; extra == "testing"
|
|
36
36
|
Requires-Dist: tox==4.23.2; extra == "testing"
|
|
37
37
|
|
|
38
|
-
[](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
|
|
39
39
|
[](https://www.python.org)
|
|
40
40
|
[](https://github.com/jakob-bagterp/timer-for-python/blob/master/LICENSE.md)
|
|
41
41
|
[](https://codecov.io/gh/jakob-bagterp/timer-for-python)
|
|
42
|
-
[](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/github-code-scanning/codeql)
|
|
43
43
|
[](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/test.yml)
|
|
44
44
|
[](https://pepy.tech/project/timer-for-python)
|
|
45
45
|
|
|
@@ -74,12 +74,12 @@ with Timer():
|
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
#### Decorator
|
|
77
|
-
Or use the `
|
|
77
|
+
Or use the `function_timer` as a function decorator:
|
|
78
78
|
|
|
79
79
|
```python
|
|
80
|
-
from timer import
|
|
80
|
+
from timer import function_timer
|
|
81
81
|
|
|
82
|
-
@
|
|
82
|
+
@function_timer()
|
|
83
83
|
def test_function():
|
|
84
84
|
# Insert your code here
|
|
85
85
|
|
|
@@ -90,7 +90,7 @@ test_function()
|
|
|
90
90
|
|
|
91
91
|
### Core Features
|
|
92
92
|
#### Decimals
|
|
93
|
-
Instead of the default value of `2` for `decimals``, you can set the output precision up to `9` in the `decimals`
|
|
93
|
+
Instead of the default value of `2` for `decimals``, you can set the output precision up to `9` in the `decimals` parameter:
|
|
94
94
|
|
|
95
95
|
```python
|
|
96
96
|
timer = Timer()
|
|
@@ -104,7 +104,7 @@ timer.stop() # Output example: 0.12345 seconds
|
|
|
104
104
|
#### Multiple Threads
|
|
105
105
|
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.
|
|
106
106
|
|
|
107
|
-
To measure the performance of multiple blocks of code, use the `thread`
|
|
107
|
+
To measure the performance of multiple blocks of code, use the `thread` parameter to name different threads:
|
|
108
108
|
|
|
109
109
|
```python
|
|
110
110
|
timer = Timer()
|
|
@@ -138,9 +138,12 @@ with Timer(thread="A")
|
|
|
138
138
|
# Output example: 6.78 seconds for thread A
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
## Become a Sponsor 🏅
|
|
142
|
+
If you find this project helpful, please consider supporting its development. Your donations will help keep it alive and growing. Every contribution, no matter the size, makes a difference.
|
|
143
|
+
|
|
144
|
+
[Donate on GitHub Sponsors](https://github.com/sponsors/jakob-bagterp)
|
|
145
|
+
|
|
146
|
+
Thank you for your support! 🙌
|
|
144
147
|
|
|
145
148
|
## Contribute
|
|
146
149
|
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).
|
{timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer_for_python.egg-info/SOURCES.txt
RENAMED
|
@@ -10,7 +10,8 @@ src/timer/constant/__init__.py
|
|
|
10
10
|
src/timer/constant/decimals.py
|
|
11
11
|
src/timer/constant/various.py
|
|
12
12
|
src/timer/controller/__init__.py
|
|
13
|
-
src/timer/decorator/
|
|
13
|
+
src/timer/decorator/__init__.py
|
|
14
|
+
src/timer/decorator/function.py
|
|
14
15
|
src/timer/error/__init__.py
|
|
15
16
|
src/timer/helper/__init__.py
|
|
16
17
|
src/timer/helper/decimals.py
|
|
@@ -24,6 +25,7 @@ src/timer/model/thread_item.py
|
|
|
24
25
|
src/timer/model/time_fractions.py
|
|
25
26
|
src/timer/model/timer.py
|
|
26
27
|
src/timer/model/timer_base.py
|
|
28
|
+
src/timer/model/abc/mkdocstrings.py
|
|
27
29
|
src/timer_for_python.egg-info/PKG-INFO
|
|
28
30
|
src/timer_for_python.egg-info/SOURCES.txt
|
|
29
31
|
src/timer_for_python.egg-info/dependency_links.txt
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import functools
|
|
2
|
-
from collections.abc import Callable
|
|
3
|
-
from typing import Any
|
|
4
|
-
|
|
5
|
-
from ..model.timer import Timer
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def benchmark_timer(function: Callable[..., Any]) -> Callable[..., Any]:
|
|
9
|
-
@functools.wraps(function)
|
|
10
|
-
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
11
|
-
with Timer(thread=function.__name__):
|
|
12
|
-
return function(*args, **kwargs)
|
|
13
|
-
|
|
14
|
-
return wrapper
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
from colorist import Color
|
|
2
|
-
|
|
3
|
-
from .. import error, helper
|
|
4
|
-
from ..model.time_fractions import TimeFractions
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def message(thread: str, fractions: TimeFractions, decimals: int) -> None:
|
|
8
|
-
try:
|
|
9
|
-
text_intro = f"Elapsed time{'' if helper.thread.is_none(thread) else f' (thread {Color.GREEN}{thread}{Color.OFF})'}:"
|
|
10
|
-
time = fractions.time
|
|
11
|
-
if time.days > 0:
|
|
12
|
-
# Format: 1d 2h 3m 4s
|
|
13
|
-
print(f"{text_intro} {time.days}d {time.hours}h {time.minutes}m {fractions.seconds_rounded()}s")
|
|
14
|
-
elif time.hours > 0:
|
|
15
|
-
# Format: 1h 2m 3s
|
|
16
|
-
print(f"{text_intro} {time.hours}h {time.minutes}m {fractions.seconds_rounded()}s")
|
|
17
|
-
elif time.minutes > 0:
|
|
18
|
-
# Format: 62.34 seconds (1m 2s)
|
|
19
|
-
print(f"{text_intro} {fractions.count_minutes_to_seconds():.{decimals}f} seconds ({time.minutes}m {fractions.seconds_rounded()}s)")
|
|
20
|
-
elif time.seconds > 0:
|
|
21
|
-
# Format: 0.123456789 seconds
|
|
22
|
-
print(f"{text_intro} {fractions.count_seconds_to_float():.{decimals}f} seconds")
|
|
23
|
-
elif time.milliseconds > 0:
|
|
24
|
-
# Format: 123.45 milliseconds
|
|
25
|
-
print(f"{text_intro} {fractions.count_milliseconds_to_float():.{decimals}f} milliseconds")
|
|
26
|
-
elif time.microseconds > 0:
|
|
27
|
-
# Format: 234.56 microseconds
|
|
28
|
-
print(f"{text_intro} {fractions.count_microseconds_to_float():.{decimals}f} microseconds")
|
|
29
|
-
else:
|
|
30
|
-
# Format: 345 nanoseconds
|
|
31
|
-
print(f"{text_intro} {time.nanoseconds} nanoseconds")
|
|
32
|
-
except Exception:
|
|
33
|
-
error.message_for_action("in the Timer's output message module", thread)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer/model/elapsed_time_fractions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer_for_python.egg-info/not-zip-safe
RENAMED
|
File without changes
|
{timer-for-python-0.7.18 → timer_for_python-0.9.0}/src/timer_for_python.egg-info/top_level.txt
RENAMED
|
File without changes
|