测量Matlab中的CPU时间使用量(以毫秒为单位) [英] Measure CPU time usage in Matlab (in milliseconds)
问题描述
如何测量Matlab在执行某些命令时所花费的时间?我正在寻找类似linux time
命令的命令,该命令返回实际使用的CPU(用户+ sys),而不是所转移的总时间,该时间可能会因其他进程的系统使用情况而有所不同.
How can I measure the time used by Matlab in the execution of some commands? I am looking for something like linux time
command, which returns the actual CPU used (user + sys), instead of the total time transcurred, which can vary depending on system usage by other processes.
此外,时间应该以毫秒为单位.
Also, the time should be returned in milliseconds.
推荐答案
You can use cputime
:
CPUTIME CPU时间(以秒为单位). CPUTIME返回已使用的CPU时间(以秒为单位) 自MATLAB启动以来,通过MATLAB流程进行的处理.
CPUTIME CPU time in seconds. CPUTIME returns the CPU time in seconds that has been used by the MATLAB process since MATLAB started.
例如:
t=cputime; your_operation; cputime-t
返回用于运行your_operation的cpu时间.
returns the cpu time used to run your_operation.
返回值可能会溢出内部表示 并环绕.
The return value may overflow the internal representation and wrap around.
还有 timeit
.
您还可以使用tic
/toc
(请参阅 Daniel的答案).
And you can also use tic
/ toc
(see Daniel's answer).
请参见一些有用的评论关于测量CPU时间.根据上面的链接,与cputime
相比,tic
/toc
和timeit
给出的估算值更准确.
See some useful comments on measuring CPU time. According to the above link, tic
/ toc
and timeit
give more accurate estimations than cputime
.
这篇关于测量Matlab中的CPU时间使用量(以毫秒为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!