当前位置:网站首页>Timing method of MATLAB program running
Timing method of MATLAB program running
2022-06-21 14:30:00 【Modest learning and progress】
Be careful : The three methods have different principles , There may be a certain gap in the results !
1、tic and toc Combine ( Use the most )
Calculation tic and toc The running time between programs , Its classic format is
tic
..........
toc
In other words, the program , Program encounter tic when Matlab Automatically start timing , Run to the toc Automatically calculate this time and the last time tic Time between . This is a bit awkward , Let's give an example to illustrate
% by dynamic of Matlab Technology Forum
% see also http://www.matlabsky.com
% contact me [email protected]
% 2009-08-18 12:08:47
clc
tic;%tic1
t1=clock;
for i=1:3
tic ;%tic2
t2=clock;
pause(3*rand)
% Calculate to the last encounter tic Time for , In other words, the time of each cycle
disp(['toc Computation first ',num2str(i),' Cycle run time :',num2str(toc)]);
% Calculate the time of each cycle
disp(['etime Computation first ',num2str(i),' Cycle run time :',num2str(etime(clock,t2))]);
% Calculate the total running time of the program
disp(['etime Calculate the running time of the program from the beginning to the present :',num2str(etime(clock,t1))]);
disp('======================================')
end
% Calculate from this time to tic2 Time for , Because the last time I met tic Is in for Cyclic i=3 when , So we calculate the time of the last cycle
disp(['toc Calculate the running time of the last cycle ',num2str(toc)])
disp(['etime Total running time of program :',num2str(etime(clock,t1))]);
The operation results are as follows , You can analyze it yourself
toc Computation first 1 Cycle run time :2.5628
etime Computation first 1 Cycle run time :2.562
etime Calculate the running time of the program from the beginning to the present :2.562
======================================
toc Computation first 2 Cycle run time :2.8108
etime Computation first 2 Cycle run time :2.813
etime Calculate the running time of the program from the beginning to the present :5.375
======================================
toc Computation first 3 Cycle run time :2.0462
etime Computation first 3 Cycle run time :2.046
etime Calculate the running time of the program from the beginning to the present :7.421
======================================
toc Calculate the running time of the last cycle 2.0479
etime Total running time of program :7.421
2、etime(t1,t2) And on and on clock coordination
To calculate t1,t2 Time difference between , It's done by calling windows The time difference of the system clock is calculated to get the running time , Form of application
t1=clock;
...........
t2=clock;
etime(t2,t1)
3、cputime Function to complete
Usage and etime be similar , Only this one uses cpu The dominant frequency of , Different from the previous principle , The format is as follows
t0=cputime
.............
t1=cputime-t0
Matlab Official recommendation tic/toc Combine ,When timing the duration of an event, use the tic and toc functions instead of clock or etime.
As for you, you can choose according to your own preferences , But use tic/toc Must pay attention to ,toc The calculation is related to the last run tic Time between , Not the first one tic, Not the second one .....
边栏推荐
- Common data processing of machine learning
- Blazer page element authorization -- use of the authorizeview component
- "My" C code specification
- Installation and application of MySQL 8.0 under Linux
- Add SSL security certificate to web site
- Compile time annotation automatically generates dataholder
- Review notes of web development technology
- Tcp/ip FAQs
- English accumulation__ annoyance
- Redisson distributed lock design from a bug
猜你喜欢

LINQ extension methods - any() vs. where() vs. exists() - LINQ extension methods - any() vs. where() vs. exists()

How is the network connected

Sliding validation tool class

MySQL failover and master-slave switchover based on MHA

Chart. JS 2.0 doughnut tooltip percentage - chart js 2.0 doughnut tooltip percentages
![[how to install MySQL 8.0 to a non system disk] [how to create a new connection with Navicat and save it to a non system disk] and [uninstall MySQL 8.0]](/img/e4/895cc829e34692a069923e226deb11.jpg)
[how to install MySQL 8.0 to a non system disk] [how to create a new connection with Navicat and save it to a non system disk] and [uninstall MySQL 8.0]

Two of my essays

Installation of oracle19c under alicloud lightweight application server linux-centos7

STM32F0-DAY1
![[googolu] takeout rebate system - business domain name of KFC configuration applet](/img/54/d30b9c08e46760dac8c3405716941f.jpg)
[googolu] takeout rebate system - business domain name of KFC configuration applet
随机推荐
Blazer page element authorization -- use of the authorizeview component
Simplified crud using code generation
Redis学习(1)——概述和常用命令
. Net synchronization mechanism and application examples
Judge password strength - Optimization
Three questions for learning new things
Make word2vec for Bert model
Use of MySQL 8.0.19 under alicloud lightweight application server linux-centos7
STM32F0-DAY1
Declare war on uncivilized code II
Compile time annotation
How is the redemption time of financial products stipulated?
Qt-4-common classes and components
Common data processing of machine learning
Pyqt environment in pycharm
使用api制作我的足迹地图
Redis learning (3) -- persistence mechanism
流量加密之C2隐藏
[test process and theory - software development process and project management]
Summary of web development technology knowledge