How to get consistant results when testing code performance
조회 수: 2 (최근 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!