@@ -167,20 +167,21 @@ def run() -> None:
167167 elif metric == "cpu" :
168168 if sys .platform == "win32" :
169169 raise NotImplementedError ("--metric cpu is not implemented on Windows" )
170- import resource # type: ignore[unreachable]
171- from resource import struct_rusage as rusage # type: ignore[attr-defined]
172-
173- stopwatch_func_c : Callable [[], rusage ] = lambda : resource .getrusage (
174- resource .RUSAGE_CHILDREN
175- )
176- delta_func_c : Callable [[rusage , rusage ], float ] = lambda r0 , r1 : (
177- r1 .ru_utime - r0 .ru_utime
178- ) + (r1 .ru_stime - r0 .ru_stime )
170+ else :
171+ import resource
172+ from resource import struct_rusage as rusage
179173
180- v0_c = stopwatch_func_c () # capture
181- run ()
182- v1_c = stopwatch_func_c () # capture
183- return delta_func_c (v0_c , v1_c )
174+ stopwatch_func_c : Callable [[], rusage ] = lambda : resource .getrusage (
175+ resource .RUSAGE_CHILDREN
176+ )
177+ delta_func_c : Callable [[rusage , rusage ], float ] = lambda r0 , r1 : (
178+ r1 .ru_utime - r0 .ru_utime
179+ ) + (r1 .ru_stime - r0 .ru_stime )
180+
181+ v0_c = stopwatch_func_c () # capture
182+ run ()
183+ v1_c = stopwatch_func_c () # capture
184+ return delta_func_c (v0_c , v1_c )
184185 else :
185186 raise AssertionError (f"Unrecognized metric: { metric !r} " )
186187
0 commit comments