bundles / numpy 2.4.4 / numpy / testing / _private / utils / measure
function
numpy.testing._private.utils:measure
Signature
def measure ( code_str , times = 1 , label = None ) Summary
Return elapsed time for executing code in the namespace of the caller.
Extended Summary
The supplied code string is compiled with the Python builtin compile. The precision of the timing is 10 milli-seconds. If the code will execute fast on this timescale, it can be executed many times to get reasonable timing accuracy.
Parameters
code_str: strThe code to be timed.
times: int, optionalThe number of times the code is executed. Default is 1. The code is only compiled once.
label: str, optionalA label to identify
code_strwith. This is passed intocompileas the second argument (for run-time error messages).
Returns
elapsed: floatTotal elapsed time in seconds for executing
code_strtimestimes.
Examples
times = 10 etime = np.testing.measure('for i in range(1000): np.sqrt(i**2)', times=times) print("Time for a single execution : ", etime / times, "s") # doctest: +SKIP
Aliases
-
numpy.testing.measure