logo

Measuring Code Execution Time in MATLAB 📂Programing

Measuring Code Execution Time in MATLAB

Methods

tic

X1=rand(2^7);
X2=rand(2^8);
X3=rand(2^9);
X4=rand(2^10);
X5=rand(2^11);
toc

Y1=imrotate(X1,45,'bicubic','crop');
toc

Y2=imrotate(X2,45,'bicubic','crop');
toc

Y3=imrotate(X3,45,'bicubic','crop');
toc

Y4=imrotate(X4,45,'bicubic','crop');
toc

Y5=imrotate(X5,45,'bicubic','crop');
toc

2020-01-0316;39;28\_.png

  • tic: Starts a stopwatch for measuring execution time.
  • toc: Returns the current time on the stopwatch. Note that it’s not measuring the time between toc and toc.

To measure the computation time of calculating Y1~Y6 in the example code above, you should enter the code as follows.

tic

X1=rand(2^7);
X2=rand(2^8);
X3=rand(2^9);
X4=rand(2^10);
X5=rand(2^11);
toc

tic
Y1=imrotate(X1,45,'bicubic','crop');
toc

tic
Y2=imrotate(X2,45,'bicubic','crop');
toc

tic
Y3=imrotate(X3,45,'bicubic','crop');
toc

tic
Y4=imrotate(X4,45,'bicubic','crop');
toc

tic
Y5=imrotate(X5,45,'bicubic','crop');
toc

2020-01-0316;45;09\_.png

Other Languages