MCPcopy Index your code
hub / github.com/python/cpython / format_duration

Function format_duration

Lib/test/libregrtest/utils.py:60–82  ·  view source on GitHub ↗
(seconds: float)

Source from the content-addressed store, hash-verified

58
59
60def format_duration(seconds: float) -> str:
61 ms = math.ceil(seconds * 1e3)
62 seconds, ms = divmod(ms, 1000)
63 minutes, seconds = divmod(seconds, 60)
64 hours, minutes = divmod(minutes, 60)
65
66 parts = []
67 if hours:
68 parts.append('%s hour' % hours)
69 if minutes:
70 parts.append('%s min' % minutes)
71 if seconds:
72 if parts:
73 # 2 min 1 sec
74 parts.append('%s sec' % seconds)
75 else:
76 # 1.0 sec
77 parts.append('%.1f sec' % (seconds + ms / 1000))
78 if not parts:
79 return '%s ms' % ms
80
81 parts = parts[:2]
82 return ' '.join(parts)
83
84
85def strip_py_suffix(names: list[str] | None) -> None:

Callers 10

display_resultMethod · 0.85
__repr__Method · 0.85
_wait_completedMethod · 0.85
wait_stoppedMethod · 0.85
get_runningFunction · 0.85
start_workersMethod · 0.85
display_resultMethod · 0.85
__str__Method · 0.85
display_summaryMethod · 0.85

Calls 2

appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…