njtierney / maxcovr

Tools in R to make it easier to solve the Maximal Coverage Location Problem
http://maxcovr.njtierney.com/
GNU General Public License v3.0
42 stars 11 forks source link

perhaps don't use dplyr::select #47

Closed njtierney closed 4 years ago

njtierney commented 7 years ago

Keep in mind that this is in microseconds (1 millionth of a second), but it might be interesting to explore


mb_1 <- 
    microbenchmark::microbenchmark(
        "dplyr::select" = dplyr::select(iris, Sepal.Width),
        "dplyr::pull" = dplyr::pull(iris, Sepal.Width),
        "[[]]" = iris[["Sepal.Width"]],
        "[]" = iris["Sepal.Width"],
        "$" = iris$Sepal.Width

    )

mb_1
#> Unit: microseconds
#>           expr      min        lq       mean    median        uq
#>  dplyr::select 2477.640 2892.6000 4161.90486 3620.8035 4585.3755
#>    dplyr::pull 1493.003 1721.4070 3972.84172 1989.4290 2458.8510
#>           [[]]    4.059    6.5525   37.26610   10.0220   15.5625
#>             []   14.226   26.3160   39.16126   38.6925   48.6375
#>              $    5.540    7.7445   15.86633   12.9025   20.8190
#>         max neval cld
#>   30316.372   100   b
#>  177265.014   100   b
#>    2585.789   100  a 
#>     127.084   100  a 
#>      48.281   100  a

ggplot2::autoplot(mb_1)

njtierney commented 6 years ago

Just an update here, since the output of $, and pull and [[]] aren't really the same:

library(bench)
library(ggplot2)

mb_1 <- mark(
    "dplyr::select" = dplyr::select(iris, Sepal.Width),
    "[]" = iris["Sepal.Width"]
  )

summary(mb_1, relative = TRUE)
#> # A tibble: 2 x 10
#>   expression      min  mean median   max `itr/sec` mem_alloc  n_gc n_itr
#>   <chr>         <dbl> <dbl>  <dbl> <dbl>     <dbl>     <dbl> <dbl> <dbl>
#> 1 dplyr::select  106.  111.   110.  15.2        1        Inf     4   1  
#> 2 []               1     1      1    1        111.       NaN     1  31.4
#> # ... with 1 more variable: total_time <dbl>

autoplot(mb_1)

Created on 2018-07-04 by the reprex package (v0.2.0).