forked from r-lib/cpp11
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum.R
More file actions
31 lines (28 loc) · 712 Bytes
/
sum.R
File metadata and controls
31 lines (28 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
pkgload::load_all("../cpp11test")
cases <- expand.grid(
len = 3e6,
vector = c("normal", "altrep"),
method = c("for", "foreach", "accumulate"),
stringsAsFactors = FALSE
)
# Add special case
cases <- do.call(rbind,
list(
list(len = 3e6, vector = "normal", method = "for2"),
list(len = 3e6, vector = "normal", method = "foreach2"),
list(len = 3e6, vector = "altrep", method = "foreach2"),
cases)
)
bench::press(
.grid = cases,
{
library(cpp11)
seq_real <- function(x) as.numeric(seq_len(x))
funs <- c("normal" = rnorm, "altrep" = seq_real)
x <- funs[[vector]](len)
fun_name <- get(sprintf("sum_dbl_%s_", method))
bench::mark(
fun_name(x)
)
}
)