1-1 ?段程?碼?計???:馬????

MATLAB tic M toc OAO²檺{pɤkAunNq{XmoӫOAMATLAB N|۰ʭp{ҪOɶCҦpG@Ӻ 10001000 üƯx}ADoϯx}pɶAiJpUG

Example 1: 01-{p/tictoc01.mtic % }lp z=inv(rand(1000)); % inv OOΨӭpϯx} toc % pElapsed time is 0.190357 seconds.

ѤWzdҡAiHoMATLAB Ob inv(rand(1000)) p⪺ɶC

Hint
  • tic M toc Ob^媺kOUθ_nAGWAǯa?!
  • @̰榹{ҨϥΪqO Intel Core i7B4 GB RAM qApGŪ̪q@̪ŧ󰪡Aұo쪺ɶiNuFI

YnϥΦhӰӭpɡAhuݭnN tic w@ܼƧYiA toc O]Ψ즹ܼơA~OҪ᪺ɶCbUCdҤAڭ̭p inv O藍Pתx}Ҫ᪺ɶA䤤ΤFӰAOp`ɶHΨCӯx}Ҫ᪺ɶG

Example 2: 01-{p/tictoc02.mtimer1=tic; % @}lp n=100*(1:10); for i=1:length(n) timer2=tic; % G}lp z=inv(rand(n(i))); % inv OOΨӭpϯx} time(i)=toc(timer2); % Gp end fprintf('Overall time = %f sec\n', toc(timer1)); % @p plot(n, time, '.-'); xlabel('Matrix dimensions'); ylabel('Elapsed time (in sec)');Overall time = 0.562098 sec

YnoɶAiHϥ clock OӶǦ^{bɶҧΦVqA]t 6 ӤAOO~BBBɡBBAҦpڭ̥iHb MATLAB JpUG

>> round(clock) ans = 2012 2 6 10 58 12

bWҤAǦ^ƦVqAN{bɶO 2012 ~ 2 6 10 58 12 Around O@άONҦǦ^ƭȡA[H|ˤJơAK\ŪC

ϥ etime OhiHǦ^ӮɶtȡAåHƪܡC]N clock M etime OX֨ϥΡANiHp@q{XɶCHeҤlӨAi clock M etime OӱoGG

Example 3: 01-{p/etime01.mt0 = clock; % O{bɶ a = inv(rand(1000)); % ϯx}B elapsedTime = etime(clock, t0) % pүӶO`ɶ elapsedTime = 0.1490

Hint
etime NO elapsed time ]gLɶ^²١C

t@ӬOO cputimeAiǦ^ MATLAB qҰʫҥeΪ CPU ɶCѩ MATLAB xܡAcputime | Windows @vT]Pentium 4 with hyperthreading running Windows^ӤǽTA]ڭ̥ثeҾǪpӥH ticBtocBclockBetime o|ӫODC


MATLAB{]pGig