numpy.testing.measure#
- testing.measure(code_str,times=1,label=None)[source]#
Return elapsed time for executing code in the namespace of the caller.
The supplied code string is compiled with the Python builtin
compile.The precision of the timing is 10 milli-seconds. If the code will executefast on this timescale, it can be executed many times to get reasonabletiming accuracy.- Parameters:
- code_strstr
The code to be timed.
- timesint, optional
The number of times the code is executed. Default is 1. The code isonly compiled once.
- labelstr, optional
A label to identifycode_str with. This is passed into
compileas the second argument (for run-time error messages).
- Returns:
- elapsedfloat
Total elapsed time in seconds for executingcode_strtimes times.
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")Time for a single execution : 0.005 s
On this page