CPU time used by MATLAB
t = cputime returns the total CPU time used by MATLAB® since it was started. The returned CPU time is expressed in seconds.
Each call to
cputime returns the total CPU time used by MATLAB up to the point when the function is called. To measure the CPU time used to
run your code, place two calls to
cputime before and after the code,
and then calculate the difference between the returned values.
Measure CPU Time to Run Code
Measure the CPU time used to run
tStart = cputime; surf(peaks(40))
tEnd = cputime - tStart
tEnd = 0.2000
For example, the CPU time for
pauseis typically small:
tStart = cputime; pause(1) tEnd = cputime - tStart
tEnd = 0.1094
However, the wall-clock time accounts for the actual time that MATLAB execution is paused:
tic pause(1) toc
Elapsed time is 1.000483 seconds.
For more information, see Measure the Performance of Your Code.
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.