There's a common saying which states that you can't change what you can't measure. Even though you can technically change your code's performance in R, you definitely won't be able to know whether a change is worth it if you don't measure it. In this section, we will introduce three tools you can use to measure your code: Rprof(), system.time(), and microbenchmark(). The first two are included in R, and the third one requires the microbenchmark package to be installed. The Rprof() tool is used to profile code, while system.time() and microbenchmark() are used to benchmark code.
- Profiling means that you measure how much time a particular implementation is spending on each of its parts.
- Benchmarking means that you compare the total amount of time to execute different implementations to compare them among themselves...