## How to measure time of matrix multiplication in matab?

I am using R2023b in case that is important.

For the sake of a project, I am trying to measure the average time of matlab when it multiplies a 96 x 192 matrix with a 192 x 1 matrix.

I have used the following code:

repeats = 100;

tTot = 0;

m = 96;

n = 192;

for j = 0:repeats

A = rand([m,n]);

A(:,1) = 1;

b = rand([n,1]);

tic

c = A * b;

tTot = tTot + toc;

end

tAvg = tTot/repeats

I have run this script a few times on my computer with different values for "repeats":

If I set repeats to 1, I get the time it takes to complete a matrix multiplication is ~1.25e-04

If I set repeats to 10, I get the time it takes to complete a matrix multiplication is ~8.75e-05

If I set repeats to 100, I get the time it takes to complete a matrix multiplication is ~5e-06

It seems quite strange to me that the average changed so much if I increase the value for repeats, so my questions are: Am I doing something wrong when I am measuring the average time? If yes, what am I doing wrong?I am using R2023b in case that is important.

For the sake of a project, I am trying to measure the average time of matlab when it multiplies a 96 x 192 matrix with a 192 x 1 matrix.

I have used the following code:

repeats = 100;

tTot = 0;

m = 96;

n = 192;

for j = 0:repeats

A = rand([m,n]);

A(:,1) = 1;

b = rand([n,1]);

tic

c = A * b;

tTot = tTot + toc;

end

tAvg = tTot/repeats

I have run this script a few times on my computer with different values for "repeats":

If I set repeats to 1, I get the time it takes to complete a matrix multiplication is ~1.25e-04

If I set repeats to 10, I get the time it takes to complete a matrix multiplication is ~8.75e-05

If I set repeats to 100, I get the time it takes to complete a matrix multiplication is ~5e-06

It seems quite strange to me that the average changed so much if I increase the value for repeats, so my questions are: Am I doing something wrong when I am measuring the average time? If yes, what am I doing wrong? I am using R2023b in case that is important.

For the sake of a project, I am trying to measure the average time of matlab when it multiplies a 96 x 192 matrix with a 192 x 1 matrix.

I have used the following code:

repeats = 100;

tTot = 0;

m = 96;

n = 192;

for j = 0:repeats

A = rand([m,n]);

A(:,1) = 1;

b = rand([n,1]);

tic

c = A * b;

tTot = tTot + toc;

end

tAvg = tTot/repeats

I have run this script a few times on my computer with different values for "repeats":

If I set repeats to 1, I get the time it takes to complete a matrix multiplication is ~1.25e-04

If I set repeats to 10, I get the time it takes to complete a matrix multiplication is ~8.75e-05

If I set repeats to 100, I get the time it takes to complete a matrix multiplication is ~5e-06

It seems quite strange to me that the average changed so much if I increase the value for repeats, so my questions are: Am I doing something wrong when I am measuring the average time? If yes, what am I doing wrong? matrix multiplication, time, measuring performance, tic toc MATLAB Answers — New Questions