Stuart’s MATLAB Videos

Watch and Learn

Knowing when to optimize code in MATLAB

I work with a lot of recent computer science graduates who are learning MATLAB. Something I see from them is they often want to choose some complicated but fast algorithm to do a task I give to them in MATLAB class. Only after they spend a long time implementing and debugging this algorithm do they see that a really naive, simple implementation of the same algorithm is fast enough for the scale and scope of the work.

It is good to know how to write super-efficient algorithms, but it is even better to know if it is at all needed. There are two ways to think of speed: computation time and time to insight. We all know computation time is how long it takes to run the program. “Time to insight” is how long from when you start thinking about the program until you get an answer. If it takes me ten minutes to implement a slow version of an algorithm and I get my answer in one minute of calculation time, I am better off than the person who takes an hour to implement an algorithm that runs in 0.1 seconds. This is especially true if the problem only needs to be solved once.

In this example, I show how I throw together a proof of concept demo to find out if it even makes sense to try to make an efficient version of an algorithm. The answer will depend on size and scope of the problem, of course. It is the process that matters most.

  • print


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