More multiplication operations require less time
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Matt J
el 29 de Ag. de 2023
Comentada: Matt J
el 31 de Ag. de 2023
I would expect the execution times for the 3 operations below to get longer and longer. Where have I misled myself? Is it an issue with tic/toc as the timing method, or something else?
A=rand(500,500,500);
tic;
A.*A;
toc;
tic;
A.*A.*A;
toc;
tic;
A.*A.*A.*A.*A.*A;
toc;
0 comentarios
Respuesta aceptada
Walter Roberson
el 29 de Ag. de 2023
It is because you are not recording the output.
I introduced T0 here because I was noticing that in my tests, T1 (the first operation) was consistently slower than T2 (the second operation), and I suspected that time to parse or something similar was being allocated against the first operation. With the T0 introduced, the measured time for A.*A reduces.
A=rand(500,500,500);
tic;
T0 = A;
toc;
tic;
T1 = A.*A;
toc;
tic;
T2 = A.*A.*A;
toc;
tic;
T3 = A.*A.*A.*A.*A.*A;
toc;
8 comentarios
Walter Roberson
el 30 de Ag. de 2023
Oh, right, it makes sense for James to have done that work! (But it would also have made sense for John to have done it as part of his high precision packages.)
Más respuestas (0)
Ver también
Categorías
Más información sobre Performance and Memory en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
