Running benchmarks
As already discussed in the previous chapters, with the help of the microbenchmark
package, we can run any number of different functions for a specified number of times on the same machine to get some reproducible results on the performance.
To this end, we have to define the functions that we want to benchmark first. These were compiled from the preceding examples:
> AGGR1 <- function() aggregate(hflights$Diverted, + by = list(hflights$DayOfWeek), FUN = mean) > AGGR2 <- function() with(hflights, aggregate(Diverted, + by = list(DayOfWeek), FUN = mean)) > AGGR3 <- function() aggregate(Diverted ~ DayOfWeek, + data = hflights, FUN = mean) > TAPPLY <- function() tapply(X = hflights$Diverted, + INDEX = hflights$DayOfWeek, FUN = mean) ...
Get Mastering Data Analysis with R now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.