Writing Efficient Code
Alice Paul · 2025
Efficient code refers to computational efficiency—writing code that executes quickly and effectively. To achieve this, it is essential to understand how R processes code and identify factors that can slow it down. This chapter introduces techniques for benchmarking code execution time using the microbenchmark package and outlines key principles for optimizing performance. Topics include leveraging fast, vectorized functions, minimizing unnecessary copies and duplicates, and adopting best practices for writing streamlined, efficient code.