Registry Mirror
搜索
Skip to content
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Files
Expand file tree
master
Breadcrumbs
python
/
clockdeco0.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
16 lines (14 loc) · 531 Bytes
master
Breadcrumbs
python
/
clockdeco0.py
Copy path
Top
File metadata and controls
Code
Blame
16 lines (14 loc) · 531 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import time
from collections.abc import Callable
from typing import Any
def clock(func: Callable) -> Callable:
"""Simple decorator that prints the elapsed time and arguments of each call."""
def clocked(*args: Any) -> Any:
t0 = time.perf_counter()
result = func(*args)
elapsed = time.perf_counter() - t0
name = func.__name__
arg_str = ', '.join(repr(arg) for arg in args)
print(f'[{elapsed:0.8f}s] {name}({arg_str}) -> {result!r}')
return result
return clocked
You can’t perform that action at this time.