Optimizing code to decrease the execution time can be a very rewarding task. Unfortunately, in most situations, optimization is almost always the last step in writing software and is only performed if absolutely necessary. If your code executes in an acceptable amount of time, optimization is not required.
Given this, why bother with code optimization? As data scientists, we often face ever-larger datasets where the code that executes on a single data element might be executed billions of times to generate results. If this code is written poorly, the analysis could literally take days to run. Further, in many scientific and numeric applications, software is computationally bound and not limited to bandwidth. As the models employed by data practitioners grow in complexity, every drop of performance matters. Why else do we optimize code? The reasons are as follows:
Time is money: If you are running software in the cloud, time is money. Each extra minute of processing is going to...