brilliant-learn-python 0.1.3__tar.gz → 0.1.6__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.
- {brilliant_learn_python-0.1.3 → brilliant_learn_python-0.1.6}/PKG-INFO +1 -1
- {brilliant_learn_python-0.1.3 → brilliant_learn_python-0.1.6}/pyproject.toml +1 -1
- {brilliant_learn_python-0.1.3 → brilliant_learn_python-0.1.6}/pyproject.toml.orig +1 -1
- brilliant_learn_python-0.1.6/src/brilliant_learn_python/context_managers/timer.py +42 -0
- brilliant_learn_python-0.1.6/src/brilliant_learn_python/decorators/__init__.py +0 -0
- brilliant_learn_python-0.1.6/src/brilliant_learn_python/decorators/timer.py +21 -0
- brilliant_learn_python-0.1.6/src/brilliant_learn_python/py.typed +0 -0
- {brilliant_learn_python-0.1.3 → brilliant_learn_python-0.1.6}/README.md +0 -0
- {brilliant_learn_python-0.1.3 → brilliant_learn_python-0.1.6}/src/brilliant_learn_python/__init__.py +0 -0
- /brilliant_learn_python-0.1.3/src/brilliant_learn_python/py.typed → /brilliant_learn_python-0.1.6/src/brilliant_learn_python/context_managers/__init__.py +0 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Context manager for measuring execution time."""
|
|
2
|
+
|
|
3
|
+
import time
|
|
4
|
+
from contextlib import AbstractContextManager
|
|
5
|
+
from types import TracebackType
|
|
6
|
+
from typing import Self
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Timer(AbstractContextManager["Timer"]):
|
|
10
|
+
"""Measure execution time."""
|
|
11
|
+
|
|
12
|
+
def __init__(self) -> None:
|
|
13
|
+
self.start: float | None = None
|
|
14
|
+
self.elapsed = 0.0
|
|
15
|
+
self.done = False
|
|
16
|
+
|
|
17
|
+
def __enter__(self) -> Self:
|
|
18
|
+
self.start = time.perf_counter()
|
|
19
|
+
self.done = False
|
|
20
|
+
return self
|
|
21
|
+
|
|
22
|
+
def __exit__(
|
|
23
|
+
self,
|
|
24
|
+
exc_type: type[BaseException] | None,
|
|
25
|
+
exc_value: BaseException | None,
|
|
26
|
+
traceback: TracebackType | None,
|
|
27
|
+
) -> None:
|
|
28
|
+
if self.start is None:
|
|
29
|
+
raise RuntimeError("Timer was never started")
|
|
30
|
+
|
|
31
|
+
self.elapsed = time.perf_counter() - self.start
|
|
32
|
+
self.done = True
|
|
33
|
+
|
|
34
|
+
def get_elapsed(self) -> float:
|
|
35
|
+
"""Return the current elapsed time in seconds."""
|
|
36
|
+
if self.start is None:
|
|
37
|
+
return 0.0
|
|
38
|
+
|
|
39
|
+
if not self.done:
|
|
40
|
+
return time.perf_counter() - self.start
|
|
41
|
+
|
|
42
|
+
return self.elapsed
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Decorator for measuring function execution time."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from brilliant_learn_python.context_managers.timer import Timer
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def timer(func: Callable[..., Any]) -> Callable[..., Any]:
|
|
10
|
+
"""Measure the execution time of a function."""
|
|
11
|
+
|
|
12
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
13
|
+
"""Execute the wrapped function and measure its duration."""
|
|
14
|
+
|
|
15
|
+
with Timer() as timer:
|
|
16
|
+
result = func(*args, **kwargs)
|
|
17
|
+
print(timer.get_elapsed())
|
|
18
|
+
|
|
19
|
+
return result
|
|
20
|
+
|
|
21
|
+
return wrapper
|
|
File without changes
|
|
File without changes
|
{brilliant_learn_python-0.1.3 → brilliant_learn_python-0.1.6}/src/brilliant_learn_python/__init__.py
RENAMED
|
File without changes
|