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

Improve sample performance for small sets #53

Closed
wants to merge 2 commits into from
Closed

Improve sample performance for small sets #53

wants to merge 2 commits into from

Conversation

rstub
Copy link
Member

@rstub rstub commented Aug 18, 2023

fixes #52

Running my first test from #52 (on a slower CPU) brings dqsample.int closer to sample.int for small sets while not compromising performance for larger ones:

library(dqrng)

m <- 1e6
n <- 1e4
prob <- dqrunif(m)
bm <- bench::mark(sample.int(m, n, replace = TRUE, prob = prob),
                  dqsample.int(m, n, replace = TRUE, prob = prob),
                  check = FALSE)
bm[, 1:4]
#> # A tibble: 2 × 4
#>   expression                                           min   median `itr/sec`
#>   <bch:expr>                                      <bch:tm> <bch:tm>     <dbl>
#> 1 sample.int(m, n, replace = TRUE, prob = prob)    13.24ms  13.95ms      70.8
#> 2 dqsample.int(m, n, replace = TRUE, prob = prob)   2.49ms   2.54ms     388.


n <- 1e4
m <- 1e1
prob <- dqrunif(m)
bm <- bench::mark(sample.int(m, n, replace = TRUE, prob = prob),
                  dqsample.int(m, n, replace = TRUE, prob = prob),
                  check = FALSE)
bm[, 1:4]
#> # A tibble: 2 × 4
#>   expression                                           min   median `itr/sec`
#>   <bch:expr>                                      <bch:tm> <bch:tm>     <dbl>
#> 1 sample.int(m, n, replace = TRUE, prob = prob)      227µs    254µs     3724.
#> 2 dqsample.int(m, n, replace = TRUE, prob = prob)    299µs    336µs     2709.

Created on 2023-08-18 with reprex v2.0.2

@rstub rstub changed the title Improve performance for small sets Improve sample performance for small sets Aug 18, 2023
@rstub rstub marked this pull request as draft August 30, 2023 12:19
@rstub
Copy link
Member Author

rstub commented Oct 13, 2023

This is handled in #72

@rstub rstub closed this Oct 13, 2023
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.

dqsample.int with arg prob sinks performance
1 participant