Comparing an alternative function's performance using the microbenchmarking package
When dealing with efficiency issues, a fast way to evaluate two alternative functions can be really useful.
This recipe is going to show you how to do this quickly and effectively and display the results of your comparison in a
ggplot diagram that is easy to understand.
This recipe is going to leverage the
microbenchmark package to compute the function comparison and the
ggplot2 package for comparison plotting:
install.packages(c("microbenchmark","ggplot2")) library(microbenchmark) library(ggplot2)
The example that follows is represented by two alternative functions to determine, for a given numeric vector, which elements of the vector are even and which ...