Stuart’s MATLAB Videos

Watch and Learn

Speeding up Doug’s solution with the profiler

Last week, I posed a Puzzler. I solved it the hard way, because I did not know any of the fancy math that the people in the comments section mentioned. I will leave the closed form solution to them and the cited references. The monte carlo solution that I came up with gave a great opportunity for code optimization via the profiler. Here is a six minute video that shows the four iterations my code took. I ended up restructuring so that I did not have clarifying “do nothing” code. I got rid of a clarifying subfunction, and I stopped keeping track of all the iterations, and just stored the final result in an accumulator. These optimizations cut the execution time by a factor of ten.
|
  • print

评论

要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。