library(tidyverse)
set.seed(406)
N <- 2000
library(rbenchmark)
benchmark(
"rowwise"={
df <- tibble(x=runif(N), y=runif(N), z=runif(N))
df %>% rowwise() %>% mutate(m = min(c(x, y, z)))
},
"pmin"={
df <- tibble(x=runif(N), y=runif(N), z=runif(N))
df %>% mutate(m = pmin(x, y, z))
},
"pmap_dbl"={
df <- tibble(x=runif(N), y=runif(N), z=runif(N))
df %>% mutate(m = pmap_dbl(list(x, y, z), min))
},
replications=1000,
columns =
c("test", "replications", "elapsed", "relative", "user.self", "sys.self")
)
#> test replications elapsed relative user.self sys.self
#> 3 pmap_dbl 1000 8.11 7.651 7.92 0
#> 2 pmin 1000 1.06 1.000 1.03 0
#> 1 rowwise 1000 7.82 7.377 7.48 0
Created on 2020-02-26 by the reprex package (v0.3.0)