73 lines
1.5 KiB
Plaintext
Raw Normal View History

2025-01-12 00:52:51 +08:00
<%@include file="includes/setup.md.rsp"%>
<%@string colname="colSums2"%>
<%@string rowname="rowSums2"%>
<%@meta title="${colname}() and ${rowname}() benchmarks"%>
<%@meta author="Henrik Bengtsson"%>
<%@meta date="2017-03-31"%>
<%@include file="${header}"%>
# <%@meta name="title"%>
This report benchmark the performance of <%=colname%>() and <%=rowname%>() against alternative methods.
## Alternative methods
* apply() + sum()
* colSums() and rowSums()
* .colSums() and .rowSums()
<% for (mode in c("integer", "double")) { %>
## Data type "<%=mode%>"
### Data
```r
<%=withCapture({
<%@include file="R/random-matrices.R"%>
data <- rmatrices(mode = mode)
})%>
```
### Results
<% for (dataLabel in names(data)) { %>
<% mprintf("%s: %s\n", mode, dataLabel) %>
#### <%=dataLabel%> <%=mode%> matrix
```r
<%=withCapture({
X <- data[[.dataLabel.]]
gc()
colStats <- microbenchmark(
colSums2 = colSums2(X, na.rm = FALSE),
.colSums = .colSums(X, m = nrow(X), n = ncol(X), na.rm = FALSE),
colSums = colSums(X, na.rm = FALSE),
"apply+sum" = apply(X, MARGIN = 2L, FUN = sum, na.rm = FALSE),
unit = "ms"
)
X <- t(X)
gc()
rowStats <- microbenchmark(
rowSums2 = rowSums2(X, na.rm = FALSE),
.rowSums = .rowSums(X, m = nrow(X), n = ncol(X), na.rm = FALSE),
rowSums = rowSums(X, na.rm = FALSE),
"apply+sum" = apply(X, MARGIN = 1L, FUN = sum, na.rm = FALSE),
unit = "ms"
)
})%>
```
<% crBenchmarkResults(colStats, rowStats, tags=c(mode, dataLabel)) %>
<% } # for (dataLabel ...) %>
<% } # for (mode ...) %>
<%@include file="${footer}"%>