質問

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 time in seconds. CPUTIME returns the CPU time in seconds that has been used by the MATLAB process since MATLAB started.

For example:

   t=cputime; your_operation; cputime-t

returns the cpu time used to run your_operation.

The return value may overflow the internal representation and wrap around.

There's also timeit.

And you can also use tic/ toc (see Daniel's answer).

See some useful comments on measuring CPU time. According to the above link, tic / toc and timeit give more accurate estimations than cputime.

他のヒント

For a simple clock time solution, use tic and toc

profile provides a detailed report code per line, you can choose between cpu time and real time.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top