-
Notifications
You must be signed in to change notification settings - Fork 293
Closed
Labels
featurea feature request or enhancementa feature request or enhancement
Description
I recently discovered every(), some() and none() and think they are great as I frequently used a pattern like any(map_lgl(...)). As @DavisVaughan pointed out in this PR they are unfortunately much slower than the map_lgl(...) pattern unless they exit early (benchmark copied from the other PR)
library(purrr)
library(vctrs)
x <- as.list(1:10000)
fn <- function(x) {
vec_is(x) || is.null(x)
}
bench::mark(
all(map_lgl(x, fn)),
every(x, fn)
)
#> # A tibble: 2 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 all(map_lgl(x, fn)) 15.9ms 20.8ms 47.7 3.91MB 30.7
#> 2 every(x, fn) 42.6ms 43.1ms 23.2 103.95KB 104.
bench::mark(
any(map_lgl(x, vec_is_list)),
some(x, vec_is_list)
)
#> # A tibble: 2 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 any(map_lgl(x, vec_is_list)) 4.63ms 5.55ms 180. 41.31KB 24.0
#> 2 some(x, vec_is_list) 26.32ms 27.23ms 36.4 8.02KB 57.2It would be great to improve their performance so that they are as fast/faster than map_lgl(...).
Metadata
Metadata
Assignees
Labels
featurea feature request or enhancementa feature request or enhancement