Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate vec_match() performance for integers #1927

Open
krlmlr opened this issue Apr 9, 2024 · 0 comments
Open

Investigate vec_match() performance for integers #1927

krlmlr opened this issue Apr 9, 2024 · 0 comments

Comments

@krlmlr
Copy link
Member

krlmlr commented Apr 9, 2024

Slower than match() by 50%?

n <- 1E6
m <- 1E3
vs <- seq(n)
index <- seq(m)
value <- list(rev = as.list(rev(index)), nchar = as.list(nchar(index)))

bench::mark(
  "Rmatch" = {
    value_nw2 <- lapply(value, function(x) {
      unname(x[match(seq_along(vs), index)])
    })
  },
  "vec_match" = {
    value_nw2 <- lapply(value, function(x) {
      unname(x[vctrs::vec_match(seq_along(vs), index)])
    })
  }
)
#> # A tibble: 2 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 Rmatch       13.6ms   14.1ms      69.7    34.6MB     279.
#> 2 vec_match    27.3ms   28.1ms      34.1    38.2MB     102.

Created on 2024-04-09 with reprex v2.1.0

Downstream: igraph/rigraph#1327 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant