colRowCounts_subset - HenrikBengtsson/matrixStats GitHub Wiki

matrixStats: Benchmark report


colCounts() and rowCounts() benchmarks on subsetted computation

This report benchmark the performance of colCounts() and rowCounts() on subsetted computation.

Data type "logical"

Data

> rmatrix <- function(nrow, ncol, mode = c("logical", "double", "integer", "index"), range = c(-100, 
+     +100), na_prob = 0) {
+     mode <- match.arg(mode)
+     n <- nrow * ncol
+     if (mode == "logical") {
+         x <- sample(c(FALSE, TRUE), size = n, replace = TRUE)
+     }     else if (mode == "index") {
+         x <- seq_len(n)
+         mode <- "integer"
+     }     else {
+         x <- runif(n, min = range[1], max = range[2])
+     }
+     storage.mode(x) <- mode
+     if (na_prob > 0) 
+         x[sample(n, size = na_prob * n)] <- NA
+     dim(x) <- c(nrow, ncol)
+     x
+ }
> rmatrices <- function(scale = 10, seed = 1, ...) {
+     set.seed(seed)
+     data <- list()
+     data[[1]] <- rmatrix(nrow = scale * 1, ncol = scale * 1, ...)
+     data[[2]] <- rmatrix(nrow = scale * 10, ncol = scale * 10, ...)
+     data[[3]] <- rmatrix(nrow = scale * 100, ncol = scale * 1, ...)
+     data[[4]] <- t(data[[3]])
+     data[[5]] <- rmatrix(nrow = scale * 10, ncol = scale * 100, ...)
+     data[[6]] <- t(data[[5]])
+     names(data) <- sapply(data, FUN = function(x) paste(dim(x), collapse = "x"))
+     data
+ }
> data <- rmatrices(mode = mode)

Results

10x10 matrix

> X <- data[["10x10"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on logical+10x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.002247 0.002308 0.0043100 0.0023660 0.002528 0.190819
2 colCounts(X, rows, cols) 0.002479 0.002549 0.0026707 0.0026115 0.002716 0.004846
3 colCounts(X[rows, cols]) 0.003019 0.003260 0.0034636 0.0033335 0.003463 0.010424
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
2 colCounts(X, rows, cols) 1.103249 1.104419 0.6196561 1.103762 1.074367 0.0253958
3 colCounts(X[rows, cols]) 1.343569 1.412478 0.8036158 1.408918 1.369858 0.0546277

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on logical+10x10 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.002144 0.002213 0.0023419 0.0022610 0.0024285 0.004592
2 rowCounts(X, cols, rows) 0.002339 0.002460 0.0045045 0.0025515 0.0026755 0.194337
3 rowCounts(X[cols, rows]) 0.002803 0.002999 0.0032171 0.0030970 0.0032425 0.007988
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts(X, cols, rows) 1.090952 1.111613 1.923423 1.128483 1.101709 42.320775
3 rowCounts(X[cols, rows]) 1.307369 1.355174 1.373686 1.369748 1.335186 1.739547

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on logical+10x10 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on logical+10x10 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 rowCounts_X_S 2.144 2.213 2.34194 2.261 2.4285 4.592
1 colCounts_X_S 2.247 2.308 4.31002 2.366 2.5280 190.819
expr min lq mean median uq max
2 rowCounts_X_S 1.000000 1.000000 1.000000 1.00000 1.000000 1.00000
1 colCounts_X_S 1.048041 1.042928 1.840363 1.04644 1.040972 41.55466

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on logical+10x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

100x100 matrix

> X <- data[["100x100"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on logical+100x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.014956 0.0159250 0.0187822 0.0163800 0.0170005 0.065345
2 colCounts(X, rows, cols) 0.026573 0.0277135 0.0301256 0.0280595 0.0286710 0.064991
3 colCounts(X[rows, cols]) 0.030900 0.0321415 0.0361838 0.0325290 0.0334035 0.094142
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 colCounts(X, rows, cols) 1.776745 1.740251 1.603940 1.713034 1.686480 0.9945826
3 colCounts(X[rows, cols]) 2.066060 2.018305 1.926489 1.985897 1.964854 1.4406917

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on logical+100x100 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.018748 0.0199265 0.0204167 0.0202775 0.0208110 0.024813
2 rowCounts(X, cols, rows) 0.021332 0.0246285 0.0255354 0.0257890 0.0265035 0.029800
3 rowCounts(X[cols, rows]) 0.026049 0.0273755 0.0285468 0.0279035 0.0284620 0.085041
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts(X, cols, rows) 1.137828 1.235967 1.250716 1.271804 1.273533 1.200983
3 rowCounts(X[cols, rows]) 1.389428 1.373824 1.398210 1.376082 1.367642 3.427276

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on logical+100x100 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on logical+100x100 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 14.956 15.9250 18.78225 16.3800 17.0005 65.345
2 rowCounts_X_S 18.748 19.9265 20.41665 20.2775 20.8110 24.813
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts_X_S 1.253544 1.251272 1.087018 1.237943 1.224141 0.379723

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on logical+100x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

1000x10 matrix

> X <- data[["1000x10"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on logical+1000x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.014952 0.0155295 0.0159807 0.0159125 0.0162535 0.023835
2 colCounts(X, rows, cols) 0.026870 0.0275695 0.0282494 0.0278060 0.0281060 0.066585
3 colCounts(X[rows, cols]) 0.030305 0.0312165 0.0318215 0.0315610 0.0319885 0.045172
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCounts(X, rows, cols) 1.797084 1.775299 1.767713 1.747431 1.729228 2.793581
3 colCounts(X[rows, cols]) 2.026819 2.010142 1.991242 1.983409 1.968099 1.895196

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on logical+1000x10 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.018717 0.0200250 0.0210584 0.0206775 0.0211855 0.063188
2 rowCounts(X, cols, rows) 0.023208 0.0262735 0.0274096 0.0273810 0.0283210 0.043252
3 rowCounts(X[cols, rows]) 0.028331 0.0292615 0.0301990 0.0298515 0.0304655 0.043113
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowCounts(X, cols, rows) 1.239942 1.312035 1.301603 1.324193 1.336811 0.6844971
3 rowCounts(X[cols, rows]) 1.513651 1.461248 1.434062 1.443671 1.438035 0.6822973

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on logical+1000x10 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on logical+1000x10 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 14.952 15.5295 15.98073 15.9125 16.2535 23.835
2 rowCounts_X_S 18.717 20.0250 21.05837 20.6775 21.1855 63.188
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.00000 1.000000 1.000000
2 rowCounts_X_S 1.251806 1.289481 1.317735 1.29945 1.303442 2.651059

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on logical+1000x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

10x1000 matrix

> X <- data[["10x1000"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on logical+10x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.016053 0.0173490 0.0181913 0.0180045 0.0187555 0.026057
3 colCounts(X[rows, cols]) 0.025500 0.0266630 0.0275438 0.0272840 0.0281125 0.037193
2 colCounts(X, rows, cols) 0.031713 0.0331705 0.0340044 0.0336375 0.0341080 0.071593
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
3 colCounts(X[rows, cols]) 1.588488 1.536861 1.514123 1.515399 1.498894 1.427371
2 colCounts(X, rows, cols) 1.975519 1.911955 1.869269 1.868283 1.818560 2.747553

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on logical+10x1000 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.018273 0.0194185 0.0206247 0.0202325 0.0207075 0.062510
2 rowCounts(X, cols, rows) 0.022733 0.0253140 0.0264121 0.0265370 0.0277050 0.030938
3 rowCounts(X[cols, rows]) 0.026197 0.0276300 0.0285089 0.0282855 0.0287930 0.045801
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowCounts(X, cols, rows) 1.244076 1.303602 1.280602 1.311603 1.337921 0.4949288
3 rowCounts(X[cols, rows]) 1.433645 1.422870 1.382266 1.398023 1.390462 0.7326988

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on logical+10x1000 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on logical+10x1000 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 16.053 17.3490 18.19127 18.0045 18.7555 26.057
2 rowCounts_X_S 18.273 19.4185 20.62474 20.2325 20.7075 62.510
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts_X_S 1.138292 1.119286 1.133771 1.123747 1.104076 2.398972

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on logical+10x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

100x1000 matrix

> X <- data[["100x1000"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on logical+100x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.177938 0.182584 0.1854838 0.1868145 0.1888510 0.200763
2 colCounts(X, rows, cols) 0.253978 0.257596 0.2662256 0.2648400 0.2708645 0.356632
3 colCounts(X[rows, cols]) 0.324466 0.328664 0.3373513 0.3360885 0.3437515 0.365653
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCounts(X, rows, cols) 1.427340 1.410836 1.435304 1.417663 1.434276 1.776383
3 colCounts(X[rows, cols]) 1.823478 1.800070 1.818764 1.799049 1.820226 1.821317

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on logical+100x1000 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.181591 0.1961155 0.2004233 0.2013035 0.2037485 0.250633
2 rowCounts(X, cols, rows) 0.239456 0.2551820 0.2620845 0.2624635 0.2682000 0.301425
3 rowCounts(X[cols, rows]) 0.242631 0.2628810 0.2689877 0.2650875 0.2720390 0.329904
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts(X, cols, rows) 1.318656 1.301182 1.307655 1.303820 1.316329 1.202655
3 rowCounts(X[cols, rows]) 1.336140 1.340440 1.342098 1.316855 1.335171 1.316283

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on logical+100x1000 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on logical+100x1000 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 177.938 182.5840 185.4838 186.8145 188.8510 200.763
2 rowCounts_X_S 181.591 196.1155 200.4233 201.3035 203.7485 250.633
expr min lq mean median uq max
1 colCounts_X_S 1.00000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts_X_S 1.02053 1.074111 1.080543 1.077558 1.078885 1.248402

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on logical+100x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

1000x100 matrix

> X <- data[["1000x100"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on logical+1000x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.172271 0.1736790 0.1772729 0.1766780 0.1788080 0.195033
3 colCounts(X[rows, cols]) 0.235371 0.2379725 0.2439298 0.2429765 0.2451605 0.321591
2 colCounts(X, rows, cols) 0.243631 0.2462140 0.2507330 0.2492495 0.2536165 0.269588
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
3 colCounts(X[rows, cols]) 1.366283 1.370186 1.376013 1.375250 1.371082 1.648906
2 colCounts(X, rows, cols) 1.414231 1.417638 1.414390 1.410756 1.418373 1.382269

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on logical+1000x100 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.189107 0.1913065 0.2006118 0.200190 0.2016930 0.356354
2 rowCounts(X, cols, rows) 0.252300 0.2594665 0.2675861 0.266562 0.2698795 0.478265
3 rowCounts(X[cols, rows]) 0.254775 0.2587900 0.2753844 0.269315 0.2737910 0.705173
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts(X, cols, rows) 1.334165 1.356287 1.333851 1.331545 1.338071 1.342106
3 rowCounts(X[cols, rows]) 1.347253 1.352751 1.372723 1.345297 1.357464 1.978855

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on logical+1000x100 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on logical+1000x100 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 172.271 173.6790 177.2729 176.678 178.808 195.033
2 rowCounts_X_S 189.107 191.3065 200.6118 200.190 201.693 356.354
expr min lq mean median uq max
1 colCounts_X_S 1.00000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts_X_S 1.09773 1.101495 1.131655 1.133078 1.127986 1.827147

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on logical+1000x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

Data type "integer"

Data

> rmatrix <- function(nrow, ncol, mode = c("logical", "double", "integer", "index"), range = c(-100, 
+     +100), na_prob = 0) {
+     mode <- match.arg(mode)
+     n <- nrow * ncol
+     if (mode == "logical") {
+         x <- sample(c(FALSE, TRUE), size = n, replace = TRUE)
+     }     else if (mode == "index") {
+         x <- seq_len(n)
+         mode <- "integer"
+     }     else {
+         x <- runif(n, min = range[1], max = range[2])
+     }
+     storage.mode(x) <- mode
+     if (na_prob > 0) 
+         x[sample(n, size = na_prob * n)] <- NA
+     dim(x) <- c(nrow, ncol)
+     x
+ }
> rmatrices <- function(scale = 10, seed = 1, ...) {
+     set.seed(seed)
+     data <- list()
+     data[[1]] <- rmatrix(nrow = scale * 1, ncol = scale * 1, ...)
+     data[[2]] <- rmatrix(nrow = scale * 10, ncol = scale * 10, ...)
+     data[[3]] <- rmatrix(nrow = scale * 100, ncol = scale * 1, ...)
+     data[[4]] <- t(data[[3]])
+     data[[5]] <- rmatrix(nrow = scale * 10, ncol = scale * 100, ...)
+     data[[6]] <- t(data[[5]])
+     names(data) <- sapply(data, FUN = function(x) paste(dim(x), collapse = "x"))
+     data
+ }
> data <- rmatrices(mode = mode)

Results

10x10 matrix

> X <- data[["10x10"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on integer+10x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.002144 0.0022385 0.0028208 0.0023435 0.0025190 0.041531
2 colCounts(X, rows, cols) 0.002373 0.0024670 0.0026433 0.0025505 0.0026750 0.004961
3 colCounts(X[rows, cols]) 0.002873 0.0031260 0.0034178 0.0032445 0.0034305 0.010647
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
2 colCounts(X, rows, cols) 1.106810 1.102077 0.9370916 1.088329 1.061929 0.1194529
3 colCounts(X[rows, cols]) 1.340019 1.396471 1.2116443 1.384468 1.361850 0.2563627

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on integer+10x10 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.002096 0.0021575 0.0022643 0.002203 0.0023065 0.004211
2 rowCounts(X, cols, rows) 0.002327 0.0023905 0.0028323 0.002459 0.0026100 0.034085
3 rowCounts(X[cols, rows]) 0.002748 0.0029110 0.0031089 0.003015 0.0031515 0.007511
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts(X, cols, rows) 1.110210 1.107995 1.250843 1.116205 1.131585 8.094277
3 rowCounts(X[cols, rows]) 1.311069 1.349247 1.372977 1.368588 1.366356 1.783662

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on integer+10x10 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on integer+10x10 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 rowCounts_X_S 2.096 2.1575 2.26432 2.2030 2.3065 4.211
1 colCounts_X_S 2.144 2.2385 2.82077 2.3435 2.5190 41.531
expr min lq mean median uq max
2 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
1 colCounts_X_S 1.022901 1.037543 1.245747 1.063777 1.092131 9.862503

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on integer+10x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

100x100 matrix

> X <- data[["100x100"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on integer+100x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.005496 0.005886 0.0060842 0.0059955 0.0061705 0.010629
2 colCounts(X, rows, cols) 0.009536 0.009996 0.0102940 0.0101595 0.0103535 0.013073
3 colCounts(X[rows, cols]) 0.013371 0.013768 0.0146739 0.0139555 0.0141520 0.073751
expr min lq mean median uq max
1 colCounts_X_S 1.00000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCounts(X, rows, cols) 1.73508 1.698267 1.691933 1.694521 1.677903 1.229937
3 colCounts(X[rows, cols]) 2.43286 2.339110 2.411813 2.327662 2.293493 6.938658

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on integer+100x100 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.006290 0.0064845 0.0066874 0.0065965 0.0067285 0.010290
2 rowCounts(X, cols, rows) 0.008769 0.0090920 0.0092881 0.0092510 0.0094130 0.010694
3 rowCounts(X[cols, rows]) 0.014183 0.0143920 0.0152446 0.0145455 0.0147010 0.072689
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts(X, cols, rows) 1.394118 1.402113 1.388899 1.402410 1.398975 1.039261
3 rowCounts(X[cols, rows]) 2.254849 2.219446 2.279622 2.205033 2.184885 7.064043

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on integer+100x100 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on integer+100x100 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 5.496 5.8860 6.08419 5.9955 6.1705 10.629
2 rowCounts_X_S 6.290 6.4845 6.68736 6.5965 6.7285 10.290
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.00000 1.0000000
2 rowCounts_X_S 1.144469 1.101682 1.099137 1.100242 1.09043 0.9681061

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on integer+100x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

1000x10 matrix

> X <- data[["1000x10"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on integer+1000x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.005173 0.0053310 0.0054957 0.0054410 0.005562 0.009227
2 colCounts(X, rows, cols) 0.009233 0.0094115 0.0099716 0.0094985 0.009600 0.054607
3 colCounts(X[rows, cols]) 0.012814 0.0131405 0.0136673 0.0132700 0.013420 0.026789
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCounts(X, rows, cols) 1.784844 1.765429 1.814454 1.745727 1.725998 5.918175
3 colCounts(X[rows, cols]) 2.477093 2.464922 2.486926 2.438890 2.412801 2.903327

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on integer+1000x10 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.006286 0.0064400 0.0069763 0.006545 0.006684 0.046441
2 rowCounts(X, cols, rows) 0.009576 0.0098110 0.0101216 0.009976 0.010136 0.023467
3 rowCounts(X[cols, rows]) 0.014943 0.0152445 0.0157533 0.015379 0.015555 0.026122
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowCounts(X, cols, rows) 1.523385 1.523447 1.450855 1.524217 1.516457 0.5053078
3 rowCounts(X[cols, rows]) 2.377187 2.367158 2.258122 2.349733 2.327199 0.5624771

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on integer+1000x10 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on integer+1000x10 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 5.173 5.331 5.49566 5.441 5.562 9.227
2 rowCounts_X_S 6.286 6.440 6.97630 6.545 6.684 46.441
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.00000 1.000000 1.000000 1.000000
2 rowCounts_X_S 1.215156 1.208028 1.26942 1.202904 1.201726 5.033163

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on integer+1000x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

10x1000 matrix

> X <- data[["10x1000"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on integer+10x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.007496 0.0078670 0.0080659 0.0079735 0.0081920 0.010714
2 colCounts(X, rows, cols) 0.011532 0.0117125 0.0124047 0.0118890 0.0120270 0.062186
3 colCounts(X[rows, cols]) 0.016238 0.0167235 0.0171649 0.0168835 0.0171365 0.027109
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCounts(X, rows, cols) 1.538420 1.488814 1.537918 1.491064 1.468140 5.804181
3 colCounts(X[rows, cols]) 2.166222 2.125779 2.128078 2.117452 2.091858 2.530241

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on integer+10x1000 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.005678 0.0059825 0.0063894 0.0061180 0.006240 0.031608
2 rowCounts(X, cols, rows) 0.009422 0.0098095 0.0100066 0.0099505 0.010155 0.011903
3 rowCounts(X[cols, rows]) 0.013411 0.0137055 0.0141973 0.0138955 0.014129 0.027171
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowCounts(X, cols, rows) 1.659387 1.639699 1.566125 1.626430 1.627404 0.3765819
3 rowCounts(X[cols, rows]) 2.361923 2.290932 2.222014 2.271249 2.264263 0.8596241

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on integer+10x1000 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on integer+10x1000 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 rowCounts_X_S 5.678 5.9825 6.38938 6.1180 6.240 31.608
1 colCounts_X_S 7.496 7.8670 8.06592 7.9735 8.192 10.714
expr min lq mean median uq max
2 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.00000 1.0000000
1 colCounts_X_S 1.320183 1.315002 1.262395 1.303285 1.31282 0.3389648

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on integer+10x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

100x1000 matrix

> X <- data[["100x1000"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on integer+100x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.034451 0.0356035 0.0371499 0.0367555 0.0372390 0.063631
2 colCounts(X, rows, cols) 0.075804 0.0766235 0.0808626 0.0800180 0.0808165 0.190477
3 colCounts(X[rows, cols]) 0.106091 0.1082505 0.1128680 0.1122005 0.1150135 0.161123
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCounts(X, rows, cols) 2.200343 2.152134 2.176658 2.177035 2.170211 2.993462
3 colCounts(X[rows, cols]) 3.079475 3.040446 3.038177 3.052618 3.088523 2.532146

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on integer+100x1000 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.033385 0.0344460 0.0365511 0.0357950 0.0375155 0.077913
2 rowCounts(X, cols, rows) 0.066724 0.0673230 0.0706222 0.0693905 0.0733705 0.082511
3 rowCounts(X[cols, rows]) 0.096389 0.0993205 0.1031130 0.1018550 0.1053390 0.162200
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts(X, cols, rows) 1.998622 1.954450 1.932152 1.938553 1.955738 1.059014
3 rowCounts(X[cols, rows]) 2.887195 2.883368 2.821067 2.845509 2.807879 2.081809

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on integer+100x1000 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on integer+100x1000 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 rowCounts_X_S 33.385 34.4460 36.55107 35.7950 37.5155 77.913
1 colCounts_X_S 34.451 35.6035 37.14990 36.7555 37.2390 63.631
expr min lq mean median uq max
2 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.0000000 1.000000
1 colCounts_X_S 1.031931 1.033603 1.016383 1.026833 0.9926297 0.816693

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on integer+100x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

1000x100 matrix

> X <- data[["1000x100"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on integer+1000x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.031942 0.0327945 0.0339031 0.0337160 0.034815 0.040094
2 colCounts(X, rows, cols) 0.067257 0.0678565 0.0705423 0.0696815 0.071716 0.086996
3 colCounts(X[rows, cols]) 0.095263 0.0966255 0.1000471 0.0987760 0.100986 0.169547
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCounts(X, rows, cols) 2.105598 2.069143 2.080705 2.066719 2.059917 2.169801
3 colCounts(X[rows, cols]) 2.982374 2.946394 2.950976 2.929648 2.900646 4.228738

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on integer+1000x100 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.042705 0.0433525 0.0460010 0.0458090 0.0467780 0.061322
2 rowCounts(X, cols, rows) 0.069610 0.0715705 0.0745829 0.0740770 0.0761745 0.095900
3 rowCounts(X[cols, rows]) 0.113582 0.1163195 0.1221983 0.1200425 0.1258025 0.221970
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts(X, cols, rows) 1.630020 1.650897 1.621333 1.617084 1.628426 1.563876
3 rowCounts(X[cols, rows]) 2.659689 2.683109 2.656428 2.620500 2.689352 3.619745

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on integer+1000x100 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on integer+1000x100 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 31.942 32.7945 33.90306 33.716 34.815 40.094
2 rowCounts_X_S 42.705 43.3525 46.00098 45.809 46.778 61.322
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts_X_S 1.336955 1.321944 1.356839 1.358672 1.343616 1.529456

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on integer+1000x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

Data type "double"

Data

> rmatrix <- function(nrow, ncol, mode = c("logical", "double", "integer", "index"), range = c(-100, 
+     +100), na_prob = 0) {
+     mode <- match.arg(mode)
+     n <- nrow * ncol
+     if (mode == "logical") {
+         x <- sample(c(FALSE, TRUE), size = n, replace = TRUE)
+     }     else if (mode == "index") {
+         x <- seq_len(n)
+         mode <- "integer"
+     }     else {
+         x <- runif(n, min = range[1], max = range[2])
+     }
+     storage.mode(x) <- mode
+     if (na_prob > 0) 
+         x[sample(n, size = na_prob * n)] <- NA
+     dim(x) <- c(nrow, ncol)
+     x
+ }
> rmatrices <- function(scale = 10, seed = 1, ...) {
+     set.seed(seed)
+     data <- list()
+     data[[1]] <- rmatrix(nrow = scale * 1, ncol = scale * 1, ...)
+     data[[2]] <- rmatrix(nrow = scale * 10, ncol = scale * 10, ...)
+     data[[3]] <- rmatrix(nrow = scale * 100, ncol = scale * 1, ...)
+     data[[4]] <- t(data[[3]])
+     data[[5]] <- rmatrix(nrow = scale * 10, ncol = scale * 100, ...)
+     data[[6]] <- t(data[[5]])
+     names(data) <- sapply(data, FUN = function(x) paste(dim(x), collapse = "x"))
+     data
+ }
> data <- rmatrices(mode = mode)

Results

10x10 matrix

> X <- data[["10x10"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on double+10x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.002166 0.0022495 0.0025563 0.0023085 0.0024025 0.022475
2 colCounts(X, rows, cols) 0.002423 0.0024690 0.0025944 0.0025490 0.0026380 0.004998
3 colCounts(X[rows, cols]) 0.003008 0.0032495 0.0034260 0.0033440 0.0034830 0.007832
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.00000 1.000000 1.0000000
2 colCounts(X, rows, cols) 1.118652 1.097577 1.014912 1.10418 1.098023 0.2223804
3 colCounts(X[rows, cols]) 1.388735 1.444543 1.340199 1.44856 1.449740 0.3484761

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on double+10x10 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.002080 0.002135 0.0024487 0.0021925 0.0023310 0.020384
2 rowCounts(X, cols, rows) 0.002277 0.002364 0.0029680 0.0024320 0.0026310 0.044465
3 rowCounts(X[cols, rows]) 0.002776 0.003009 0.0034619 0.0030740 0.0032455 0.028448
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts(X, cols, rows) 1.094712 1.107260 1.212078 1.109236 1.128700 2.181368
3 rowCounts(X[cols, rows]) 1.334615 1.409368 1.413800 1.402052 1.392321 1.395604

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on double+10x10 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on double+10x10 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 rowCounts_X_S 2.080 2.1350 2.44867 2.1925 2.3310 20.384
1 colCounts_X_S 2.166 2.2495 2.55630 2.3085 2.4025 22.475
expr min lq mean median uq max
2 rowCounts_X_S 1.000000 1.00000 1.000000 1.000000 1.000000 1.00000
1 colCounts_X_S 1.041346 1.05363 1.043954 1.052908 1.030674 1.10258

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on double+10x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

100x100 matrix

> X <- data[["100x100"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on double+100x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.008043 0.008513 0.0102419 0.0086815 0.0109740 0.020431
2 colCounts(X, rows, cols) 0.011426 0.011750 0.0159653 0.0120705 0.0213945 0.035573
3 colCounts(X[rows, cols]) 0.026096 0.026396 0.0324221 0.0265765 0.0427830 0.110035
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.00000 1.000000 1.000000
2 colCounts(X, rows, cols) 1.420614 1.380242 1.558823 1.39037 1.949563 1.741129
3 colCounts(X[rows, cols]) 3.244560 3.100670 3.165623 3.06128 3.898579 5.385688

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on double+100x100 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.008175 0.0083980 0.0088239 0.0085045 0.0086350 0.015719
2 rowCounts(X, cols, rows) 0.011173 0.0115305 0.0119324 0.0116870 0.0118755 0.021638
3 rowCounts(X[cols, rows]) 0.016311 0.0166865 0.0180458 0.0168805 0.0170895 0.065964
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts(X, cols, rows) 1.366728 1.373006 1.352283 1.374214 1.375275 1.376551
3 rowCounts(X[cols, rows]) 1.995229 1.986961 2.045103 1.984890 1.979097 4.196450

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on double+100x100 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on double+100x100 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 rowCounts_X_S 8.175 8.398 8.82389 8.5045 8.635 15.719
1 colCounts_X_S 8.043 8.513 10.24192 8.6815 10.974 20.431
expr min lq mean median uq max
2 rowCounts_X_S 1.0000000 1.000000 1.000000 1.000000 1.000000 1.000000
1 colCounts_X_S 0.9838532 1.013694 1.160704 1.020812 1.270874 1.299765

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on double+100x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

1000x10 matrix

> X <- data[["1000x10"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on double+1000x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.006852 0.0070605 0.0072335 0.007179 0.0072950 0.011488
2 colCounts(X, rows, cols) 0.010001 0.0102500 0.0109706 0.010395 0.0105430 0.062343
3 colCounts(X[rows, cols]) 0.022905 0.0231390 0.0234086 0.023244 0.0234055 0.033792
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCounts(X, rows, cols) 1.459574 1.451739 1.516646 1.447973 1.445237 5.426793
3 colCounts(X[rows, cols]) 3.342820 3.277247 3.236155 3.237777 3.208430 2.941504

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on double+1000x10 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.007731 0.0079720 0.0103602 0.0080715 0.0083555 0.047387
2 rowCounts(X, cols, rows) 0.011249 0.0116270 0.0137319 0.0119290 0.0121415 0.039464
3 rowCounts(X[cols, rows]) 0.016894 0.0174715 0.0235917 0.0176865 0.0179330 0.109830
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowCounts(X, cols, rows) 1.455051 1.458480 1.325450 1.477916 1.453115 0.8328022
3 rowCounts(X[cols, rows]) 2.185228 2.191608 2.277161 2.191228 2.146251 2.3177243

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on double+1000x10 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on double+1000x10 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 6.852 7.0605 7.23347 7.1790 7.2950 11.488
2 rowCounts_X_S 7.731 7.9720 10.36016 8.0715 8.3555 47.387
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts_X_S 1.128284 1.129099 1.432253 1.124321 1.145374 4.124913

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on double+1000x10 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

10x1000 matrix

> X <- data[["10x1000"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on double+10x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.008270 0.008571 0.0088871 0.0087415 0.0089455 0.012358
2 colCounts(X, rows, cols) 0.012117 0.012465 0.0133405 0.0126575 0.0128990 0.071094
3 colCounts(X[rows, cols]) 0.017551 0.018219 0.0185476 0.0183810 0.0187755 0.024144
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCounts(X, rows, cols) 1.465175 1.454323 1.501099 1.447978 1.441954 5.752873
3 colCounts(X[rows, cols]) 2.122249 2.125656 2.087013 2.102728 2.098876 1.953714

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on double+10x1000 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.007726 0.0081005 0.0088008 0.0082590 0.0084790 0.048638
2 rowCounts(X, cols, rows) 0.011144 0.0114290 0.0117761 0.0115640 0.0118250 0.015960
3 rowCounts(X[cols, rows]) 0.015795 0.0162430 0.0166161 0.0164035 0.0166565 0.033213
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowCounts(X, cols, rows) 1.442402 1.410901 1.338065 1.400170 1.394622 0.3281385
3 rowCounts(X[cols, rows]) 2.044395 2.005185 1.888019 1.986136 1.964442 0.6828611

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on double+10x1000 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on double+10x1000 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
2 rowCounts_X_S 7.726 8.1005 8.80081 8.2590 8.4790 48.638
1 colCounts_X_S 8.270 8.5710 8.88714 8.7415 8.9455 12.358
expr min lq mean median uq max
2 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
1 colCounts_X_S 1.070412 1.058083 1.009809 1.058421 1.055018 0.2540812

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on double+10x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

100x1000 matrix

> X <- data[["100x1000"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on double+100x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.049440 0.0524380 0.0539035 0.0539400 0.055366 0.067887
2 colCounts(X, rows, cols) 0.078341 0.0811430 0.0855115 0.0851465 0.087653 0.179032
3 colCounts(X[rows, cols]) 0.196544 0.2037805 0.2146001 0.2149090 0.222064 0.244480
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCounts(X, rows, cols) 1.584567 1.547408 1.586381 1.578541 1.583156 2.637206
3 colCounts(X[rows, cols]) 3.975404 3.886123 3.981191 3.984223 4.010837 3.601279

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on double+100x1000 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.054829 0.0577135 0.0612434 0.061151 0.062375 0.105587
2 rowCounts(X, cols, rows) 0.082418 0.0849970 0.0901913 0.090001 0.092821 0.136203
3 rowCounts(X[cols, rows]) 0.123533 0.1299695 0.1377765 0.137303 0.140325 0.278118
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts(X, cols, rows) 1.503183 1.472740 1.472669 1.471783 1.488112 1.289960
3 rowCounts(X[cols, rows]) 2.253059 2.251977 2.249655 2.245311 2.249699 2.634017

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on double+100x1000 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on double+100x1000 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 49.440 52.4380 53.90349 53.940 55.366 67.887
2 rowCounts_X_S 54.829 57.7135 61.24341 61.151 62.375 105.587
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts_X_S 1.109001 1.100604 1.136168 1.133686 1.126594 1.555335

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on double+100x1000 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

1000x100 matrix

> X <- data[["1000x100"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> value <- 42
> colStats <- microbenchmark(colCounts_X_S = colCounts(X_S, value = value, na.rm = FALSE), `colCounts(X, rows, cols)` = colCounts(X, 
+     value = value, na.rm = FALSE, rows = rows, cols = cols), `colCounts(X[rows, cols])` = colCounts(X[rows, 
+     cols], value = value, na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> rowStats <- microbenchmark(rowCounts_X_S = rowCounts(X_S, value = value, na.rm = FALSE), `rowCounts(X, cols, rows)` = rowCounts(X, 
+     value = value, na.rm = FALSE, rows = cols, cols = rows), `rowCounts(X[cols, rows])` = rowCounts(X[cols, 
+     rows], value = value, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on double+1000x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 0.048826 0.049702 0.0517852 0.0518185 0.0527520 0.065642
2 colCounts(X, rows, cols) 0.075753 0.076358 0.0794161 0.0784035 0.0814750 0.096335
3 colCounts(X[rows, cols]) 0.117300 0.120151 0.1262839 0.1243840 0.1275025 0.251628
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCounts(X, rows, cols) 1.551489 1.536316 1.533566 1.513041 1.544491 1.467582
3 colCounts(X[rows, cols]) 2.402409 2.417428 2.438607 2.400378 2.417017 3.833338

Table: Benchmarking of rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on double+1000x100 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCounts_X_S 0.054137 0.0551325 0.0577975 0.0587340 0.0590865 0.069548
2 rowCounts(X, cols, rows) 0.084963 0.0869950 0.0912077 0.0924395 0.0927485 0.127833
3 rowCounts(X[cols, rows]) 0.127433 0.1305020 0.1386157 0.1375325 0.1398425 0.263158
expr min lq mean median uq max
1 rowCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts(X, cols, rows) 1.569407 1.577926 1.578057 1.573867 1.569707 1.838054
3 rowCounts(X[cols, rows]) 2.353898 2.367061 2.398300 2.341616 2.366742 3.783833

Figure: Benchmarking of colCounts_X_S(), colCounts(X, rows, cols)() and colCounts(X[rows, cols])() on double+1000x100 data as well as rowCounts_X_S(), rowCounts(X, cols, rows)() and rowCounts(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCounts_X_S() and rowCounts_X_S() on double+1000x100 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCounts_X_S 48.826 49.7020 51.78525 51.8185 52.7520 65.642
2 rowCounts_X_S 54.137 55.1325 57.79748 58.7340 59.0865 69.548
expr min lq mean median uq max
1 colCounts_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCounts_X_S 1.108774 1.109261 1.116099 1.133456 1.120081 1.059505

Figure: Benchmarking of colCounts_X_S() and rowCounts_X_S() on double+1000x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

Appendix

Session information

R version 3.6.1 Patched (2019-08-27 r77078)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS

Matrix products: default
BLAS:   /home/hb/software/R-devel/R-3-6-branch/lib/R/lib/libRblas.so
LAPACK: /home/hb/software/R-devel/R-3-6-branch/lib/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] microbenchmark_1.4-6    matrixStats_0.55.0-9000 ggplot2_3.2.1          
[4] knitr_1.24              R.devices_2.16.0        R.utils_2.9.0          
[7] R.oo_1.22.0             R.methodsS3_1.7.1       history_0.0.0-9002     

loaded via a namespace (and not attached):
 [1] Biobase_2.45.0       bit64_0.9-7          splines_3.6.1       
 [4] network_1.15         assertthat_0.2.1     highr_0.8           
 [7] stats4_3.6.1         blob_1.2.0           robustbase_0.93-5   
[10] pillar_1.4.2         RSQLite_2.1.2        backports_1.1.4     
[13] lattice_0.20-38      glue_1.3.1           digest_0.6.20       
[16] colorspace_1.4-1     sandwich_2.5-1       Matrix_1.2-17       
[19] XML_3.98-1.20        lpSolve_5.6.13.3     pkgconfig_2.0.2     
[22] genefilter_1.66.0    purrr_0.3.2          ergm_3.10.4         
[25] xtable_1.8-4         mvtnorm_1.0-11       scales_1.0.0        
[28] tibble_2.1.3         annotate_1.62.0      IRanges_2.18.2      
[31] TH.data_1.0-10       withr_2.1.2          BiocGenerics_0.30.0 
[34] lazyeval_0.2.2       mime_0.7             survival_2.44-1.1   
[37] magrittr_1.5         crayon_1.3.4         statnet.common_4.3.0
[40] memoise_1.1.0        laeken_0.5.0         R.cache_0.13.0      
[43] MASS_7.3-51.4        R.rsp_0.43.1         tools_3.6.1         
[46] multcomp_1.4-10      S4Vectors_0.22.1     trust_0.1-7         
[49] munsell_0.5.0        AnnotationDbi_1.46.1 compiler_3.6.1      
[52] rlang_0.4.0          grid_3.6.1           RCurl_1.95-4.12     
[55] cwhmisc_6.6          rappdirs_0.3.1       labeling_0.3        
[58] bitops_1.0-6         base64enc_0.1-3      boot_1.3-23         
[61] gtable_0.3.0         codetools_0.2-16     DBI_1.0.0           
[64] markdown_1.1         R6_2.4.0             zoo_1.8-6           
[67] dplyr_0.8.3          bit_1.1-14           zeallot_0.1.0       
[70] parallel_3.6.1       Rcpp_1.0.2           vctrs_0.2.0         
[73] DEoptimR_1.0-8       tidyselect_0.2.5     xfun_0.9            
[76] coda_0.19-3         

Total processing time was 33.66 secs.

Reproducibility

To reproduce this report, do:

html <- matrixStats:::benchmark('colRowCounts_subset')

Copyright Dongcan Jiang. Last updated on 2019-09-10 20:36:47 (-0700 UTC). Powered by RSP.

<script> var link = document.createElement('link'); link.rel = 'icon'; link.href = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAA21BMVEUAAAAAAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8BAf4CAv0DA/wdHeIeHuEfH+AgIN8hId4lJdomJtknJ9g+PsE/P8BAQL9yco10dIt1dYp3d4h4eIeVlWqWlmmXl2iYmGeZmWabm2Tn5xjo6Bfp6Rb39wj4+Af//wA2M9hbAAAASXRSTlMAAQIJCgsMJSYnKD4/QGRlZmhpamtsbautrrCxuru8y8zN5ebn6Pn6+///////////////////////////////////////////LsUNcQAAAS9JREFUOI29k21XgkAQhVcFytdSMqMETU26UVqGmpaiFbL//xc1cAhhwVNf6n5i5z67M2dmYOyfJZUqlVLhkKucG7cgmUZTybDz6g0iDeq51PUr37Ds2cy2/C9NeES5puDjxuUk1xnToZsg8pfA3avHQ3lLIi7iWRrkv/OYtkScxBIMgDee0ALoyxHQBJ68JLCjOtQIMIANF7QG9G9fNnHvisCHBVMKgSJgiz7nE+AoBKrAPA3MgepvgR9TSCasrCKH0eB1wBGBFdCO+nAGjMVGPcQb5bd6mQRegN6+1axOs9nGfYcCtfi4NQosdtH7dB+txFIpXQqN1p9B/asRHToyS0jRgpV7nk4nwcq1BJ+x3Gl/v7S9Wmpp/aGquum7w3ZDyrADFYrl8vHBH+ev9AUASW1dmU4h4wAAAABJRU5ErkJggg==" document.getElementsByTagName('head')[0].appendChild(link); </script>
⚠️ **GitHub.com Fallback** ⚠️