Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/dabeaz/python-cookbook
/ timethis
Function
timethis
src/9/defining_context_managers_the_easy_way/example1.py:5–11 ·
view source on GitHub ↗
(label)
Source
from the content-addressed store, hash-verified
3
4
@contextmanager
5
def
timethis(label):
6
start = time.time()
7
try
:
8
yield
9
finally:
10
end = time.time()
11
print(
'{}: {}'
.format(label, end - start))
12
13
# Example use
14
with
timethis(
'counting'
):
Callers
1
example1.py
File · 0.70
Calls
no outgoing calls
Tested by
no test coverage detected