timer-for-python 0.9.11__py3-none-any.whl → 0.9.13__py3-none-any.whl
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/constant/various.py +2 -0
- timer/helper/output.py +6 -6
- timer/helper/time_fractions.py +3 -3
- timer/model/time_fractions.py +23 -13
- timer/version.py +1 -1
- {timer_for_python-0.9.11.dist-info → timer_for_python-0.9.13.dist-info}/METADATA +10 -9
- {timer_for_python-0.9.11.dist-info → timer_for_python-0.9.13.dist-info}/RECORD +9 -9
- {timer_for_python-0.9.11.dist-info → timer_for_python-0.9.13.dist-info}/WHEEL +1 -1
- {timer_for_python-0.9.11.dist-info → timer_for_python-0.9.13.dist-info}/licenses/LICENSE.md +0 -0
timer/constant/various.py
CHANGED
timer/helper/output.py
CHANGED
|
@@ -11,24 +11,24 @@ def message(thread: str, fractions: TimeFractions, decimals: int) -> None:
|
|
|
11
11
|
time = fractions.time
|
|
12
12
|
if time.days > 0:
|
|
13
13
|
# Format: 1d 2h 3m 4s
|
|
14
|
-
print(f"{intro} {time.days}d {time.hours}h {time.minutes}m {fractions.
|
|
14
|
+
print(f"{intro} {time.days}d {time.hours}h {time.minutes}m {fractions.total_seconds_rounded}s{thread_info}")
|
|
15
15
|
elif time.hours > 0:
|
|
16
16
|
# Format: 1h 2m 3s
|
|
17
|
-
print(f"{intro} {time.hours}h {time.minutes}m {fractions.
|
|
17
|
+
print(f"{intro} {time.hours}h {time.minutes}m {fractions.total_seconds_rounded}s{thread_info}")
|
|
18
18
|
elif time.minutes > 0:
|
|
19
19
|
# Format: 62.34 seconds (1m 2s)
|
|
20
20
|
print(
|
|
21
|
-
f"{intro} {fractions.
|
|
21
|
+
f"{intro} {fractions.total_minutes_as_seconds:.{decimals}f} seconds ({time.minutes}m {fractions.total_seconds_rounded}s){thread_info}"
|
|
22
22
|
)
|
|
23
23
|
elif time.seconds > 0:
|
|
24
24
|
# Format: 0.123456789 seconds
|
|
25
|
-
print(f"{intro} {fractions.
|
|
25
|
+
print(f"{intro} {fractions.total_seconds:.{decimals}f} seconds{thread_info}")
|
|
26
26
|
elif time.milliseconds > 0:
|
|
27
27
|
# Format: 123.45 milliseconds
|
|
28
|
-
print(f"{intro} {fractions.
|
|
28
|
+
print(f"{intro} {fractions.total_milliseconds:.{decimals}f} milliseconds{thread_info}")
|
|
29
29
|
elif time.microseconds > 0:
|
|
30
30
|
# Format: 234.56 microseconds
|
|
31
|
-
print(f"{intro} {fractions.
|
|
31
|
+
print(f"{intro} {fractions.total_microseconds:.{decimals}f} microseconds{thread_info}")
|
|
32
32
|
else:
|
|
33
33
|
# Format: 345 nanoseconds
|
|
34
34
|
print(f"{intro} {time.nanoseconds} nanoseconds{thread_info}")
|
timer/helper/time_fractions.py
CHANGED
|
@@ -4,10 +4,10 @@ from ..model.elapsed_time_fractions import ElapsedTimeFractions
|
|
|
4
4
|
def calculate_time_fractions(elapsed_time_ns: int) -> ElapsedTimeFractions:
|
|
5
5
|
"""Elapsed time is in nanoseconds and should be calculated as difference between start and stop time using on the time.perf_counter_ns() function."""
|
|
6
6
|
|
|
7
|
-
microseconds, nanoseconds = divmod(elapsed_time_ns,
|
|
7
|
+
microseconds, nanoseconds = divmod(elapsed_time_ns, 1_000)
|
|
8
8
|
# As divmod() can be slow, let's return 0s as a tuple if divmod() isn't needed:
|
|
9
|
-
milliseconds, microseconds = divmod(microseconds,
|
|
10
|
-
seconds, milliseconds = divmod(milliseconds,
|
|
9
|
+
milliseconds, microseconds = divmod(microseconds, 1_000) if microseconds > 0 else (0, 0)
|
|
10
|
+
seconds, milliseconds = divmod(milliseconds, 1_000) if milliseconds > 0 else (0, 0)
|
|
11
11
|
minutes, seconds = divmod(seconds, 60) if seconds > 0 else (0, 0)
|
|
12
12
|
hours, minutes = divmod(minutes, 60) if minutes > 0 else (0, 0)
|
|
13
13
|
days, hours = divmod(hours, 24) if hours > 0 else (0, 0)
|
timer/model/time_fractions.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from .. import helper
|
|
2
|
+
from ..constant.various import SECONDS_PER_MINUTE
|
|
2
3
|
from .elapsed_time_fractions import ElapsedTimeFractions
|
|
3
4
|
|
|
4
5
|
|
|
@@ -8,23 +9,32 @@ class TimeFractions:
|
|
|
8
9
|
def __init__(self, elapsed_time_ns: int) -> None:
|
|
9
10
|
self.time: ElapsedTimeFractions = helper.time_fractions.calculate_time_fractions(elapsed_time_ns)
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
@property
|
|
13
|
+
def total_microseconds(self) -> float:
|
|
14
|
+
"""Count the total microseconds and anything below that."""
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
"""This could potentially be faster by dividing self.microseconds by a 1000 directly, yet we don't want to lose precision in the decimals."""
|
|
16
|
+
return self.time.microseconds + self.time.nanoseconds / 1_000
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
@property
|
|
19
|
+
def total_milliseconds(self) -> float:
|
|
20
|
+
"""Count the total milliseconds and anything below that. This could potentially be faster by dividing self.microseconds by a 1,000 directly, yet we don't want to lose precision in the decimals."""
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
"""This could potentially be faster by dividing self.milliseconds by a 1000 directly, yet we don't want to lose precision in the decimals."""
|
|
22
|
+
return self.time.milliseconds + self.total_microseconds / 1_000
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
@property
|
|
25
|
+
def total_seconds(self) -> float:
|
|
26
|
+
"""Count the total seconds and anything below that. This could potentially be faster by dividing self.milliseconds by a 1,000 directly, yet we don't want to lose precision in the decimals."""
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
"""For instance, if 2 seconds and 567 milliseconds, ensure it'll be rounded up to 3 seconds."""
|
|
28
|
+
return self.time.seconds + self.total_milliseconds / 1_000
|
|
26
29
|
|
|
27
|
-
|
|
30
|
+
@property
|
|
31
|
+
def total_seconds_rounded(self) -> float:
|
|
32
|
+
"""Count the total seconds and anything below that. For instance, if 2 seconds and 567 milliseconds, ensure it'll be rounded up to 3 seconds."""
|
|
28
33
|
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
return int(round(self.total_seconds, 0))
|
|
35
|
+
|
|
36
|
+
@property
|
|
37
|
+
def total_minutes_as_seconds(self) -> float:
|
|
38
|
+
"""Count the total minutes as seconds and anything below that."""
|
|
39
|
+
|
|
40
|
+
return self.time.minutes * SECONDS_PER_MINUTE + self.total_seconds
|
timer/version.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version_info__ = (0, 9,
|
|
1
|
+
__version_info__ = (0, 9, 13)
|
|
2
2
|
__version__ = ".".join(map(str, __version_info__))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: timer-for-python
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.13
|
|
4
4
|
Summary: Lightweight 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
|
|
5
5
|
Project-URL: Bug Tracker, https://github.com/jakob-bagterp/timer-for-python/issues
|
|
6
6
|
Project-URL: Documentation, https://jakob-bagterp.github.io/timer-for-python/
|
|
@@ -20,17 +20,18 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.12
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.13
|
|
22
22
|
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
23
24
|
Requires-Python: >=3.10
|
|
24
|
-
Requires-Dist: colorist==1.8.
|
|
25
|
+
Requires-Dist: colorist==1.8.15
|
|
25
26
|
Description-Content-Type: text/markdown
|
|
26
27
|
|
|
27
|
-
[](https://github.com/jakob-bagterp/timer-for-python/releases/latest)
|
|
29
|
+
[](https://www.python.org)
|
|
30
|
+
[](https://github.com/jakob-bagterp/timer-for-python/blob/master/LICENSE.md)
|
|
30
31
|
[](https://codecov.io/gh/jakob-bagterp/timer-for-python)
|
|
31
32
|
[](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/github-code-scanning/codeql)
|
|
32
33
|
[](https://github.com/jakob-bagterp/timer-for-python/actions/workflows/test.yml)
|
|
33
|
-
[](https://pepy.tech/project/timer-for-python)
|
|
34
35
|
|
|
35
36
|
# ⏳ Timer for Python ⌛️
|
|
36
37
|
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.
|
|
@@ -49,7 +50,7 @@ timer.start()
|
|
|
49
50
|
|
|
50
51
|
# Insert your code here
|
|
51
52
|
|
|
52
|
-
timer.stop()
|
|
53
|
+
timer.stop() # Output example: 12.34 seconds
|
|
53
54
|
```
|
|
54
55
|
|
|
55
56
|
#### Context Manager
|
|
@@ -87,7 +88,7 @@ timer.start(decimals=5)
|
|
|
87
88
|
|
|
88
89
|
# Insert your code here
|
|
89
90
|
|
|
90
|
-
timer.stop()
|
|
91
|
+
timer.stop() # Output example: 0.12345 seconds
|
|
91
92
|
```
|
|
92
93
|
|
|
93
94
|
#### Multiple Threads
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
timer/__init__.py,sha256=X7Z5wKwhKDIzSnmtYR5Img5iGp13-vfgMWSWGFfHGq4,158
|
|
2
2
|
timer/conftest.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
3
|
timer/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
timer/version.py,sha256=
|
|
4
|
+
timer/version.py,sha256=n3S-N4BlSg4aqocIBujpKIRAd9OVpt-Bfism_dV0_Cw,81
|
|
5
5
|
timer/constant/__init__.py,sha256=0e0W-lRc5xtJ9LSsEyq4o6zKckaRweAvrntmFE1gisE,67
|
|
6
6
|
timer/constant/decimals.py,sha256=9SKe-IbFIbXY-Mps6bSYBqaWuxLiRlsa3rNmT_oDbiM,53
|
|
7
|
-
timer/constant/various.py,sha256=
|
|
7
|
+
timer/constant/various.py,sha256=2RLj9vLGk0AKRsdSiNKCtwQplsT_50GY1qvFK_GDKFY,142
|
|
8
8
|
timer/controller/__init__.py,sha256=lN-rF2nX4pCZ-Z8l7kJTlk4mmsInfLZ52NY4S6Wf6A0,1662
|
|
9
9
|
timer/decorator/__init__.py,sha256=juqd9PbXs4yg45zMJ7BHAOPQjb7sgEbWE9InBtGZhfo,24
|
|
10
10
|
timer/decorator/function.py,sha256=LBbtkIA9p1T-HgIh6OMgtJTyOmo6aM5TuIwK0E7ieQk,3570
|
|
11
11
|
timer/error/__init__.py,sha256=pjjCgDtv2TJ8-eBnq98buWPIDt-Znfj1Gbk9CXzJhQE,1197
|
|
12
12
|
timer/helper/__init__.py,sha256=kYe7PVpjG7UeamvAvohgiIleefsGslx1tJvuNO5_oSQ,117
|
|
13
13
|
timer/helper/decimals.py,sha256=3WXpSLkf8ySbOMgE98ieTvs1ILaSA1ymennlQdMxaNM,1629
|
|
14
|
-
timer/helper/output.py,sha256=
|
|
15
|
-
timer/helper/time_fractions.py,sha256=
|
|
14
|
+
timer/helper/output.py,sha256=i2CDkKAncKrLormmOScWQPcBnysNdslJpwRNDIVQjak,1721
|
|
15
|
+
timer/helper/time_fractions.py,sha256=nlLUf-ni1osDhG9IzGmlZz_m07hTBXF3tC394v5e0Po,1092
|
|
16
16
|
timer/helper/thread/__init__.py,sha256=sIXJTI05fLVUT71DbiBf0axFpxOn0L9sRe23KUOC8Gw,471
|
|
17
17
|
timer/helper/thread/list.py,sha256=6rT-0zRG9xuwbQsLpFdTeoa-O1NqWiCbznzsC31e2SA,1485
|
|
18
18
|
timer/model/__init__.py,sha256=m-K3jgLBqKUwBNJByKeLiGQCzCVZC07N12_SmkbGxyg,145
|
|
19
19
|
timer/model/elapsed_time_fractions.py,sha256=UXfABMQ14kgsEHjQmef2PKMgtdqKF9zPyrmA9_TQHrg,282
|
|
20
20
|
timer/model/thread_item.py,sha256=7i7oH2eghF5K_k4Oed-i6to85VoPlJw3_g0U5ilB_VY,199
|
|
21
|
-
timer/model/time_fractions.py,sha256=
|
|
21
|
+
timer/model/time_fractions.py,sha256=IRUgEwGMD18A4kjCoO9vvn60FUNXxnqhK7IWeSTMPJc,1670
|
|
22
22
|
timer/model/timer.py,sha256=cQblVIvhIU-Fhh3L4EvYVZNFkNWj8ABv1A1detaQMGo,7190
|
|
23
23
|
timer/model/timer_base.py,sha256=TZ_ROsJWM0hLioXnYTFv_WMqN31c1i2yng2IU8vteWc,1015
|
|
24
24
|
timer/model/abc/mkdocstrings.py,sha256=3JrQVkW0D4YW7hOVOr9Jd35gH7-Z5o8y0bNjQz1EAzw,350
|
|
25
|
-
timer_for_python-0.9.
|
|
26
|
-
timer_for_python-0.9.
|
|
27
|
-
timer_for_python-0.9.
|
|
28
|
-
timer_for_python-0.9.
|
|
25
|
+
timer_for_python-0.9.13.dist-info/METADATA,sha256=ySQNaGia3y0bq8XtX4R7V_fbBtPJSluInQjBM8AvUVo,6001
|
|
26
|
+
timer_for_python-0.9.13.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
27
|
+
timer_for_python-0.9.13.dist-info/licenses/LICENSE.md,sha256=bV6mZhoYf6kHYGgsG3ArjpF_tjOweaI7QZKRvmzkUMI,1085
|
|
28
|
+
timer_for_python-0.9.13.dist-info/RECORD,,
|
|
File without changes
|