How to get consistant results when testing code performance
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have functions to make searches in Simulink models. I want to test which algorithm has better performance. I use the "Run and Time" to check the running time. But the performance varies a lot each time. What I have done is simplely closing other software, running "bdclose all" before starting the test. Is there anything I can do to achieve a more consistant results?
0 comentarios
Respuestas (2)
Walter Roberson
el 17 de Feb. de 2025
However according to https://steveeddins.com/story-of-timeit/ if the code to be timed 11 times would take more than 15 seconds, then the number of calls will be reduced, possibly down to as few as 3 times.
0 comentarios
John D'Errico
el 17 de Feb. de 2025
A single time test will be susceptible to anything that attracts the attention of your CPU. And sadly, your CPU suffers from computational ADHD.
So run multiple tests, then take the average. Better yet, take N tests, then drop the slowest and fastest times, and take the average of the other N-2, so a trimmed mean. Or just use the median, instead of the average.
Absolutely minimize everything else that is running on your computer. DON'T check your mail during a test. Close your web browser. Make sure nothing is automatically performing a backup while the test is happening.
1 comentario
Walter Roberson
el 17 de Feb. de 2025
Better yet, close your mail program during the test, if you are using a mail application.
And your anti-virus.
And automatic disk defragmenters.
And minesweeper.
And external performance monitors.
And if you are working on MacOS, any of ~100-ish background daemons, including searchlight indexing, and Slack, and branded mouse helpers, and MATLAB Connector, and Siri, and keyboard helpers...
Ver también
Categorías
Más información sobre Inputs 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!