MCPcopy Create free account
hub / github.com/ScalingIntelligence/tokasaurus / timer

Function timer

tokasaurus/utils.py:31–55  ·  view source on GitHub ↗
(
    name: str, enable: bool = True, min_ms: float | None = None, profile: bool = False
)

Source from the content-addressed store, hash-verified

29
30@contextmanager
31def timer(
32 name: str, enable: bool = True, min_ms: float | None = None, profile: bool = False
33):
34 if not enable:
35 yield
36 return
37
38 if profile:
39 profiler = cProfile.Profile()
40 profiler.enable()
41
42 start = time.time()
43
44 yield
45
46 end = time.time()
47
48 if profile:
49 profiler.disable()
50
51 ms = (end - start) * 1000
52 if min_ms is None or ms > min_ms:
53 print(f"timer {name}: {ms:.2f}ms")
54 if profile:
55 profiler.print_stats()
56
57
58@contextmanager

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected