matlab: Calculate the running time of the program

demand

When you need to quantitatively evaluate the execution efficiency of the code, you need to know the running time of the program.

achieve

In matlab, it can be easily achieved with tic and toc commands. Matlab automatically starts timing when the program encounters tic, and automatically calculates the time between this time and the latest tic when it runs to toc.

Examples

%test脚本。通过tic,toc命令直接输出程序运行时间。
tic
pause(1)
t1=toc
pause(1)
t2=toc

Results of the

>> test
时间已过 1.000123 秒。
时间已过 2.000327 秒。
%test脚本。若想将用运行时间记录下来,则这样使用toc
tic
pause(1)
t1=toc
pause(1)
t2=toc

operation result

>> test

t1 =

    1.0001


t2 =

    2.0004
Published 47 original articles · Like 33 · Visit 310,000+

Guess you like

Origin blog.csdn.net/kaever/article/details/71407127