Skip to content

Improve sample performance for small sets#53

Closed
rstub wants to merge 2 commits into
masterfrom
issue/52
Closed

Improve sample performance for small sets#53
rstub wants to merge 2 commits into
masterfrom
issue/52

Conversation

@rstub

@rstub rstub commented Aug 18, 2023

Copy link
Copy Markdown
Member

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

rstub commented Oct 13, 2023

Copy link
Copy Markdown
Member Author

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