How to get consistant results when testing code performance
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Walter Roberson
2025-2-17
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 个评论
John D'Errico
2025-2-17
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 个评论
Walter Roberson
2025-2-17
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...
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Inputs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!