74 lines
1.4 KiB
Plaintext
Raw Normal View History

2025-01-12 00:52:51 +08:00
<%@include file="includes/setup.md.rsp"%>
<%@string colname="colAnys"%>
<%@string rowname="rowAnys"%>
<%@meta title="${colname}() and ${rowname}() benchmarks"%>
<%@meta author="Henrik Bengtsson"%>
<%@meta date="2014-11-18"%>
<%@include file="${header}"%>
# <%@meta name="title"%>
This report benchmark the performance of <%=colname%>() and <%=rowname%>() against alternative methods.
## Alternative methods
* apply() + any()
* colSums() > 0 or rowSums() > 0
## Data
```r
<%=withCapture({
<%@include file="R/random-matrices.R"%>
data <- rmatrices(mode = "logical")
})%>
```
## Results
<% for (dataLabel in names(data)) { %>
<% message(dataLabel) %>
### <%=dataLabel%> matrix
```r
<%=withCapture({
X <- data[[.dataLabel.]]
gc()
colStats <- microbenchmark(
colAnys = colAnys(X),
"apply+any" = apply(X, MARGIN = 2L, FUN = any),
"colSums > 0" = (colSums(X) > 0L),
unit = "ms"
)
X <- t(X)
gc()
rowStats <- microbenchmark(
rowAnys = rowAnys(X),
"apply+any" = apply(X, MARGIN = 1L, FUN = any),
"rowSums > 0" = (rowSums(X) > 0L),
unit = "ms"
)
})%>
```
<% crBenchmarkResults(colStats, rowStats, tags=dataLabel) %>
<% } # for (dataLabel ...) %>
<%@include file="${footer}"%>
<%---------------------------------------------------------------------------
HISTORY:
2014-11-18
o Created.
---------------------------------------------------------------------------%>