performance-decorator 0.1.0__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.
@@ -0,0 +1,37 @@
1
+ """Measure and report function execution time."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from functools import wraps
6
+ from time import perf_counter
7
+ from typing import Any, Callable, TypeVar, cast
8
+
9
+ F = TypeVar("F", bound=Callable[..., Any])
10
+
11
+
12
+ def performance(function: F) -> F:
13
+ """Decorate a function to print and expose its execution time.
14
+
15
+ The wrapped function keeps its original return value. Its most recent
16
+ execution time, in seconds, is available as ``function.last_duration``.
17
+ A history of all completed calls is available as
18
+ ``function.execution_times``.
19
+ """
20
+
21
+ @wraps(function)
22
+ def timed(*args: Any, **kwargs: Any) -> Any:
23
+ start = perf_counter()
24
+ try:
25
+ return function(*args, **kwargs)
26
+ finally:
27
+ duration = perf_counter() - start
28
+ timed.last_duration = duration # type: ignore[attr-defined]
29
+ timed.execution_times.append(duration) # type: ignore[attr-defined]
30
+ print(f"{function.__name__} took {duration:.6f} seconds")
31
+
32
+ timed.last_duration = None # type: ignore[attr-defined]
33
+ timed.execution_times = [] # type: ignore[attr-defined]
34
+ return cast(F, timed)
35
+
36
+
37
+ __all__ = ["performance"]
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.5
2
+ Name: performance-decorator
3
+ Version: 0.1.0
4
+ Summary: A small decorator that measures and reports function execution time.
5
+ Project-URL: Homepage, https://pypi.org/project/performance-decorator/
6
+ Project-URL: Repository, https://github.com/leonardobartolelli/performance-decorator
7
+ Author: Leonardo Bartolelli
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: decorator,performance,timing
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Requires-Python: >=3.8
19
+ Description-Content-Type: text/markdown
20
+
21
+ # performance-decorator
22
+
23
+ Measure function execution time with a simple decorator.
24
+
25
+ ## Installation
26
+
27
+ ```bash
28
+ pip install performance-decorator
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ```python
34
+ from performance import performance
35
+
36
+
37
+ @performance
38
+ def calculate():
39
+ return sum(range(100_000))
40
+
41
+
42
+ result = calculate()
43
+ print(result)
44
+ print(calculate.last_duration) # elapsed time in seconds
45
+ print(calculate.execution_times) # duration of every completed call
46
+ ```
47
+
48
+ Each call prints a line such as:
49
+
50
+ ```text
51
+ calculate took 0.002341 seconds
52
+ ```
53
+
54
+ The wrapped function's return value and metadata are preserved. Timing is
55
+ recorded even when the wrapped function raises an exception.
@@ -0,0 +1,5 @@
1
+ performance/__init__.py,sha256=l_3WA7_1qOArSj-LNwaY3tTE__fi4QAvAAPVKmJabhs,1211
2
+ performance_decorator-0.1.0.dist-info/METADATA,sha256=57dyXzDKcXUPTMG1na3H7pzE6aF0K8IbFvjh_AAFxZg,1480
3
+ performance_decorator-0.1.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
4
+ performance_decorator-0.1.0.dist-info/licenses/LICENSE,sha256=m9cK8EamhvVjlrznqxp8g3sAOLYJc8tcT5UOioXJK68,1076
5
+ performance_decorator-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.4
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Leonardo Bartolelli
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.