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

Faster is_sparse_vector() #76

Merged
merged 2 commits into from
Sep 20, 2024
Merged

Faster is_sparse_vector() #76

merged 2 commits into from
Sep 20, 2024

Conversation

EmilHvitfeldt
Copy link
Member

Now all the calculations are done in C.

  • if x isn't an altrep vector return FALSE right away.
  • if the package attribute of the altrep. vector is {sparsevctrs} return TRUE.

With this PR

library(sparsevctrs)

vec <- sparse_double(1, 1, 1)

bench::mark(
  is_sparse_vector(vec)
)
#> # A tibble: 1 × 6
#>   expression                 min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>            <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 is_sparse_vector(vec)    164ns    246ns  3177418.    2.26KB        0

bench::mark(
  is_sparse_vector(letters)
)
#> # A tibble: 1 × 6
#>   expression                     min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>                <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 is_sparse_vector(letters)    123ns    205ns  4795355.    1.92KB        0

Before this PR

library(sparsevctrs)

vec <- sparse_double(1, 1, 1)

bench::mark(
  is_sparse_vector(vec)
)
#> # A tibble: 1 × 6
#>   expression                 min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>            <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 is_sparse_vector(vec)    656ns    779ns  1025601.    7.34KB        0

bench::mark(
  is_sparse_vector(letters)
)
#> # A tibble: 1 × 6
#>   expression                     min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>                <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 is_sparse_vector(letters)    205ns    246ns  3777087.    1.92KB        0

@EmilHvitfeldt EmilHvitfeldt merged commit 4b4774c into main Sep 20, 2024
11 checks passed
@EmilHvitfeldt EmilHvitfeldt deleted the faster-is_sparse_vector branch September 20, 2024 20:37
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

Successfully merging this pull request may close these issues.

1 participant