1414# Imports
1515#-----------------------------------------------------------------------------
1616
17+ from __future__ import annotations
18+
1719import time
20+ from typing import Any , Callable
1821
1922#-----------------------------------------------------------------------------
2023# Code
@@ -56,7 +59,7 @@ def clock():
5659 u ,s = resource .getrusage (resource .RUSAGE_SELF )[:2 ]
5760 return u + s
5861
59- def clock2 ():
62+ def clock2 () -> tuple [ float , float ] :
6063 """clock2() -> (t_user,t_system)
6164
6265 Similar to clock(), but return a tuple of user/system times."""
@@ -67,14 +70,19 @@ def clock2():
6770 # time.process_time() for everything...
6871 clocku = clocks = clock = time .process_time
6972
70- def clock2 ():
73+ def clock2 () -> tuple [ float , float ] :
7174 """Under windows, system CPU time can't be measured.
7275
7376 This just returns process_time() and zero."""
7477 return time .process_time (), 0.0
7578
7679
77- def timings_out (reps ,func ,* args ,** kw ):
80+ def timings_out (
81+ reps : int ,
82+ func : Callable [..., Any ],
83+ * args : Any ,
84+ ** kw : Any ,
85+ ) -> tuple [float , float , Any ]:
7886 """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output)
7987
8088 Execute a function reps times, return a tuple with the elapsed total
@@ -103,7 +111,12 @@ def timings_out(reps,func,*args,**kw):
103111 return tot_time ,av_time ,out
104112
105113
106- def timings (reps ,func ,* args ,** kw ):
114+ def timings (
115+ reps : int ,
116+ func : Callable [..., Any ],
117+ * args : Any ,
118+ ** kw : Any ,
119+ ) -> tuple [float , float ]:
107120 """timings(reps,func,*args,**kw) -> (t_total,t_per_call)
108121
109122 Execute a function reps times, return a tuple with the elapsed total CPU
@@ -113,7 +126,7 @@ def timings(reps,func,*args,**kw):
113126 return timings_out (reps ,func ,* args ,** kw )[0 :2 ]
114127
115128
116- def timing (func , * args , ** kw ) :
129+ def timing (func : Callable [..., Any ], * args : Any , ** kw : Any ) -> float :
117130 """timing(func,*args,**kw) -> t_total
118131
119132 Execute a function once, return the elapsed total CPU time in
0 commit comments