Measuring performance describes how to find the bottlenecks in your code using line profiling. Accept these possibilities and move on to the next candidate. Others you may need to pass over and accept either because there is no quick and easy solution or because the code is already well optimised and no significant improvement is possible. Some you will not get to because you’ve met your goal. This means you will not eliminate all bottlenecks. To enforce this advice, you should set a goal time for your code and optimise only up to that goal. Be pragmatic: don’t spend hours of your time to save seconds of computer time. Don’t! Your time is valuable and is better spent analysing your data, not eliminating possible inefficiencies in your code. It’s easy to get caught up in trying to remove all bottlenecks. I’ll also suggest a general strategy for performance optimisation that helps ensure that your faster code will still be correct code. It’s difficult to provide general advice on improving performance, but I try my best with six techniques that can be applied in many situations. Only once you’ve identified the most important bottlenecks can you attempt to eliminate them. Instead of relying on your intuition, you should profile your code: use realistic inputs and measure the run-time of each individual operation. Repeat until your code is “fast enough.”Įven experienced programmers have a hard time identifying bottlenecks in their code.Try to eliminate it (you may not succeed but that’s ok).Find the biggest bottleneck (the slowest part of your code).Optimising code to make it run faster is an iterative process: “Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered.” You’re reading the first edition of Advanced R for the latest on this topic, see the Measuring performance chapter in the second edition.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |