colRowMeans2_subset - HenrikBengtsson/matrixStats GitHub Wiki

matrixStats: Benchmark report


colMeans2() and rowMeans2() benchmarks on subsetted computation

This report benchmark the performance of colMeans2() and rowMeans2() on subsetted computation.

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 integer 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]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3136175 167.5    5709258 305.0  5709258 305.0
Vcells 6002295  45.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMeans2_X_S = colMeans2(X_S, na.rm = FALSE), `colMeans2(X, rows, cols)` = colMeans2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMeans2(X[rows, cols])` = colMeans2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3135354 167.5    5709258 305.0  5709258 305.0
Vcells 6000266  45.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMeans2_X_S = rowMeans2(X_S, na.rm = FALSE), `rowMeans2(X, cols, rows)` = rowMeans2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMeans2(X[cols, rows])` = rowMeans2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMeans2_X_S(), colMeans2(X, rows, cols)() and colMeans2(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 colMeans2_X_S 0.001012 0.0010510 0.0020686 0.001078 0.0011485 0.095374
2 colMeans2(X, rows, cols) 0.001151 0.0012030 0.0012986 0.001238 0.0013625 0.002528
3 colMeans2(X[rows, cols]) 0.001505 0.0016795 0.0019137 0.001777 0.0018630 0.009139
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
2 colMeans2(X, rows, cols) 1.137352 1.144624 0.6277621 1.148423 1.186330 0.0265062
3 colMeans2(X[rows, cols]) 1.487154 1.598002 0.9251009 1.648423 1.622116 0.0958228

Table: Benchmarking of rowMeans2_X_S(), rowMeans2(X, cols, rows)() and rowMeans2(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 rowMeans2_X_S 0.001020 0.0010495 0.0011459 0.0010730 0.0011835 0.003048
2 rowMeans2(X, cols, rows) 0.001145 0.0012030 0.0024958 0.0012345 0.0013545 0.119225
3 rowMeans2(X[cols, rows]) 0.001490 0.0016965 0.0019195 0.0017670 0.0019030 0.006960
expr min lq mean median uq max
1 rowMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMeans2(X, cols, rows) 1.122549 1.146260 2.178058 1.150513 1.144487 39.115814
3 rowMeans2(X[cols, rows]) 1.460784 1.616484 1.675161 1.646785 1.607943 2.283465

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

Table: Benchmarking of colMeans2_X_S() and rowMeans2_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 rowMeans2_X_S 1.020 1.0495 1.14586 1.073 1.1835 3.048
1 colMeans2_X_S 1.012 1.0510 2.06865 1.078 1.1485 95.374
expr min lq mean median uq max
2 rowMeans2_X_S 1.0000000 1.000000 1.000000 1.00000 1.0000000 1.00000
1 colMeans2_X_S 0.9921569 1.001429 1.805325 1.00466 0.9704267 31.29068

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

100x100 integer 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]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3133736 167.4    5709258 305.0  5709258 305.0
Vcells 5667703  43.3   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMeans2_X_S = colMeans2(X_S, na.rm = FALSE), `colMeans2(X, rows, cols)` = colMeans2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMeans2(X[rows, cols])` = colMeans2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3133730 167.4    5709258 305.0  5709258 305.0
Vcells 5672786  43.3   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMeans2_X_S = rowMeans2(X_S, na.rm = FALSE), `rowMeans2(X, cols, rows)` = rowMeans2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMeans2(X[cols, rows])` = rowMeans2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMeans2_X_S(), colMeans2(X, rows, cols)() and colMeans2(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 colMeans2_X_S 0.005694 0.0061670 0.0063227 0.0062875 0.0064465 0.009233
2 colMeans2(X, rows, cols) 0.006572 0.0071280 0.0073177 0.0072620 0.0074115 0.009410
3 colMeans2(X[rows, cols]) 0.013319 0.0138425 0.0145661 0.0139635 0.0141635 0.058807
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMeans2(X, rows, cols) 1.154197 1.155829 1.157359 1.154990 1.149694 1.019170
3 colMeans2(X[rows, cols]) 2.339129 2.244608 2.303762 2.220835 2.197084 6.369219

Table: Benchmarking of rowMeans2_X_S(), rowMeans2(X, cols, rows)() and rowMeans2(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 rowMeans2_X_S 0.005697 0.0061965 0.0064094 0.0063030 0.0064685 0.011850
2 rowMeans2(X, cols, rows) 0.006557 0.0071110 0.0072179 0.0072015 0.0073030 0.008348
3 rowMeans2(X[cols, rows]) 0.013179 0.0137340 0.0145504 0.0139095 0.0141270 0.057671
expr min lq mean median uq max
1 rowMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowMeans2(X, cols, rows) 1.150957 1.147583 1.126135 1.142551 1.129010 0.7044726
3 rowMeans2(X[cols, rows]) 2.313323 2.216413 2.270157 2.206806 2.183969 4.8667511

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

Table: Benchmarking of colMeans2_X_S() and rowMeans2_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 colMeans2_X_S 5.694 6.1670 6.32274 6.2875 6.4465 9.233
2 rowMeans2_X_S 5.697 6.1965 6.40942 6.3030 6.4685 11.850
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
2 rowMeans2_X_S 1.000527 1.004784 1.013709 1.002465 1.003413 1.28344

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

1000x10 integer 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]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3134491 167.4    5709258 305.0  5709258 305.0
Vcells 5671775  43.3   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMeans2_X_S = colMeans2(X_S, na.rm = FALSE), `colMeans2(X, rows, cols)` = colMeans2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMeans2(X[rows, cols])` = colMeans2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3134482 167.4    5709258 305.0  5709258 305.0
Vcells 5676853  43.4   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMeans2_X_S = rowMeans2(X_S, na.rm = FALSE), `rowMeans2(X, cols, rows)` = rowMeans2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMeans2(X[cols, rows])` = rowMeans2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMeans2_X_S(), colMeans2(X, rows, cols)() and colMeans2(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 colMeans2_X_S 0.006722 0.0069635 0.0071653 0.0070890 0.0073120 0.009325
2 colMeans2(X, rows, cols) 0.007619 0.0078585 0.0082350 0.0080095 0.0081170 0.029352
3 colMeans2(X[rows, cols]) 0.014012 0.0145155 0.0149172 0.0147140 0.0149725 0.022443
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMeans2(X, rows, cols) 1.133442 1.128527 1.149287 1.129849 1.110093 3.147668
3 colMeans2(X[rows, cols]) 2.084499 2.084512 2.081857 2.075610 2.047661 2.406756

Table: Benchmarking of rowMeans2_X_S(), rowMeans2(X, cols, rows)() and rowMeans2(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 rowMeans2_X_S 0.006780 0.0069645 0.0072516 0.0070650 0.007216 0.022338
2 rowMeans2(X, cols, rows) 0.007701 0.0078305 0.0083144 0.0079920 0.008159 0.028389
3 rowMeans2(X[cols, rows]) 0.015216 0.0155620 0.0159080 0.0157035 0.016001 0.022441
expr min lq mean median uq max
1 rowMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMeans2(X, cols, rows) 1.135841 1.124345 1.146560 1.131210 1.130682 1.270884
3 rowMeans2(X[cols, rows]) 2.244248 2.234475 2.193735 2.222718 2.217433 1.004611

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

Table: Benchmarking of colMeans2_X_S() and rowMeans2_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
2 rowMeans2_X_S 6.780 6.9645 7.25157 7.065 7.216 22.338
1 colMeans2_X_S 6.722 6.9635 7.16533 7.089 7.312 9.325
expr min lq mean median uq max
2 rowMeans2_X_S 1.0000000 1.0000000 1.0000000 1.000000 1.000000 1.0000000
1 colMeans2_X_S 0.9914454 0.9998564 0.9881074 1.003397 1.013304 0.4174501

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

10x1000 integer 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]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3134694 167.5    5709258 305.0  5709258 305.0
Vcells 5672624  43.3   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMeans2_X_S = colMeans2(X_S, na.rm = FALSE), `colMeans2(X, rows, cols)` = colMeans2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMeans2(X[rows, cols])` = colMeans2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3134688 167.5    5709258 305.0  5709258 305.0
Vcells 5677707  43.4   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMeans2_X_S = rowMeans2(X_S, na.rm = FALSE), `rowMeans2(X, cols, rows)` = rowMeans2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMeans2(X[cols, rows])` = rowMeans2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMeans2_X_S(), colMeans2(X, rows, cols)() and colMeans2(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 colMeans2_X_S 0.005980 0.0061935 0.0064048 0.0063075 0.006527 0.008118
2 colMeans2(X, rows, cols) 0.008556 0.0088300 0.0092065 0.0089355 0.009063 0.032344
3 colMeans2(X[rows, cols]) 0.014404 0.0147800 0.0151480 0.0149365 0.015171 0.022208
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMeans2(X, rows, cols) 1.430769 1.425688 1.437450 1.416647 1.388540 3.984233
3 colMeans2(X[rows, cols]) 2.408696 2.386373 2.365113 2.368054 2.324345 2.735649

Table: Benchmarking of rowMeans2_X_S(), rowMeans2(X, cols, rows)() and rowMeans2(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 rowMeans2_X_S 0.006087 0.0063315 0.0068189 0.0064500 0.0066295 0.036717
2 rowMeans2(X, cols, rows) 0.008336 0.0084690 0.0086735 0.0085570 0.0087445 0.010745
3 rowMeans2(X[cols, rows]) 0.013369 0.0138670 0.0143932 0.0140035 0.0143590 0.032030
expr min lq mean median uq max
1 rowMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowMeans2(X, cols, rows) 1.369476 1.337598 1.271985 1.326667 1.319029 0.2926437
3 rowMeans2(X[cols, rows]) 2.196320 2.190160 2.110785 2.171085 2.165925 0.8723480

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

Table: Benchmarking of colMeans2_X_S() and rowMeans2_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
1 colMeans2_X_S 5.980 6.1935 6.40476 6.3075 6.5270 8.118
2 rowMeans2_X_S 6.087 6.3315 6.81890 6.4500 6.6295 36.717
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMeans2_X_S 1.017893 1.022281 1.064661 1.022592 1.015704 4.522912

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

100x1000 integer 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]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3134893 167.5    5709258 305.0  5709258 305.0
Vcells 5695287  43.5   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMeans2_X_S = colMeans2(X_S, na.rm = FALSE), `colMeans2(X, rows, cols)` = colMeans2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMeans2(X[rows, cols])` = colMeans2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3134887 167.5    5709258 305.0  5709258 305.0
Vcells 5745370  43.9   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMeans2_X_S = rowMeans2(X_S, na.rm = FALSE), `rowMeans2(X, cols, rows)` = rowMeans2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMeans2(X[cols, rows])` = rowMeans2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMeans2_X_S(), colMeans2(X, rows, cols)() and colMeans2(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 colMeans2_X_S 0.047693 0.0480815 0.0483832 0.048213 0.0484440 0.053227
2 colMeans2(X, rows, cols) 0.058319 0.0587005 0.0599412 0.058904 0.0591065 0.148362
3 colMeans2(X[rows, cols]) 0.118974 0.1194300 0.1202710 0.119697 0.1203885 0.139045
expr min lq mean median uq max
1 colMeans2_X_S 1.00000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMeans2(X, rows, cols) 1.22280 1.220854 1.238886 1.221745 1.220099 2.787345
3 colMeans2(X[rows, cols]) 2.49458 2.483907 2.485803 2.482671 2.485107 2.612302

Table: Benchmarking of rowMeans2_X_S(), rowMeans2(X, cols, rows)() and rowMeans2(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 rowMeans2_X_S 0.048577 0.0490745 0.0502173 0.0492735 0.049849 0.101283
2 rowMeans2(X, cols, rows) 0.074924 0.0754840 0.0761068 0.0757975 0.076091 0.085869
3 rowMeans2(X[cols, rows]) 0.111337 0.1122705 0.1144994 0.1129130 0.114409 0.173477
expr min lq mean median uq max
1 rowMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowMeans2(X, cols, rows) 1.542376 1.538151 1.515551 1.538301 1.526430 0.8478126
3 rowMeans2(X[cols, rows]) 2.291969 2.287756 2.280080 2.291556 2.295111 1.7127948

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

Table: Benchmarking of colMeans2_X_S() and rowMeans2_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
1 colMeans2_X_S 47.693 48.0815 48.38318 48.2130 48.444 53.227
2 rowMeans2_X_S 48.577 49.0745 50.21728 49.2735 49.849 101.283
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
2 rowMeans2_X_S 1.018535 1.020652 1.037908 1.021996 1.029003 1.90285

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

1000x100 integer 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]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3135112 167.5    5709258 305.0  5709258 305.0
Vcells 5696080  43.5   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMeans2_X_S = colMeans2(X_S, na.rm = FALSE), `colMeans2(X, rows, cols)` = colMeans2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMeans2(X[rows, cols])` = colMeans2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3135103 167.5    5709258 305.0  5709258 305.0
Vcells 5746158  43.9   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMeans2_X_S = rowMeans2(X_S, na.rm = FALSE), `rowMeans2(X, cols, rows)` = rowMeans2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMeans2(X[cols, rows])` = rowMeans2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMeans2_X_S(), colMeans2(X, rows, cols)() and colMeans2(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 colMeans2_X_S 0.052139 0.0526350 0.0530807 0.0528350 0.0531475 0.058491
2 colMeans2(X, rows, cols) 0.056382 0.0568355 0.0571660 0.0571275 0.0573860 0.058743
3 colMeans2(X[rows, cols]) 0.115089 0.1157060 0.1178964 0.1160285 0.1168615 0.198967
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMeans2(X, rows, cols) 1.081379 1.079804 1.076964 1.081244 1.079750 1.004308
3 colMeans2(X[rows, cols]) 2.207350 2.198271 2.221078 2.196054 2.198815 3.401669

Table: Benchmarking of rowMeans2_X_S(), rowMeans2(X, cols, rows)() and rowMeans2(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 rowMeans2_X_S 0.053237 0.0538700 0.0545218 0.0541565 0.0546360 0.067469
2 rowMeans2(X, cols, rows) 0.074706 0.0754095 0.0760186 0.0756445 0.0759925 0.102267
3 rowMeans2(X[cols, rows]) 0.124307 0.1255445 0.1288937 0.1267330 0.1286625 0.222305
expr min lq mean median uq max
1 rowMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMeans2(X, cols, rows) 1.403272 1.399842 1.394279 1.396776 1.390887 1.515763
3 rowMeans2(X[cols, rows]) 2.334974 2.330509 2.364076 2.340125 2.354903 3.294921

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

Table: Benchmarking of colMeans2_X_S() and rowMeans2_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 colMeans2_X_S 52.139 52.635 53.08073 52.8350 53.1475 58.491
2 rowMeans2_X_S 53.237 53.870 54.52182 54.1565 54.6360 67.469
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMeans2_X_S 1.021059 1.023464 1.027149 1.025012 1.028007 1.153494

Figure: Benchmarking of colMeans2_X_S() and rowMeans2_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 double 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]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3135330 167.5    5709258 305.0  5709258 305.0
Vcells 5787185  44.2   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMeans2_X_S = colMeans2(X_S, na.rm = FALSE), `colMeans2(X, rows, cols)` = colMeans2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMeans2(X[rows, cols])` = colMeans2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3135312 167.5    5709258 305.0  5709258 305.0
Vcells 5787348  44.2   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMeans2_X_S = rowMeans2(X_S, na.rm = FALSE), `rowMeans2(X, cols, rows)` = rowMeans2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMeans2(X[cols, rows])` = rowMeans2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMeans2_X_S(), colMeans2(X, rows, cols)() and colMeans2(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 colMeans2_X_S 0.001048 0.0010715 0.0014291 0.0010960 0.0011680 0.028541
2 colMeans2(X, rows, cols) 0.001187 0.0012495 0.0013424 0.0012710 0.0013140 0.004488
3 colMeans2(X[rows, cols]) 0.001631 0.0018775 0.0020696 0.0019435 0.0020545 0.009945
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.0000000 1.000000 1.00000 1.0000000
2 colMeans2(X, rows, cols) 1.132634 1.166122 0.9393604 1.159671 1.12500 0.1572475
3 colMeans2(X[rows, cols]) 1.556298 1.752217 1.4481562 1.773266 1.75899 0.3484461

Table: Benchmarking of rowMeans2_X_S(), rowMeans2(X, cols, rows)() and rowMeans2(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 rowMeans2_X_S 0.001037 0.0010640 0.0011604 0.0010835 0.0011735 0.003148
2 rowMeans2(X, cols, rows) 0.001208 0.0012345 0.0016028 0.0012510 0.0013245 0.031066
3 rowMeans2(X[cols, rows]) 0.001510 0.0017415 0.0019289 0.0018165 0.0019705 0.008154
expr min lq mean median uq max
1 rowMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMeans2(X, cols, rows) 1.164899 1.160244 1.381306 1.154592 1.128675 9.868488
3 rowMeans2(X[cols, rows]) 1.456123 1.636748 1.662283 1.676511 1.679165 2.590216

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

Table: Benchmarking of colMeans2_X_S() and rowMeans2_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 rowMeans2_X_S 1.037 1.0640 1.16038 1.0835 1.1735 3.148
1 colMeans2_X_S 1.048 1.0715 1.42910 1.0960 1.1680 28.541
expr min lq mean median uq max
2 rowMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.0000000 1.000000
1 colMeans2_X_S 1.010608 1.007049 1.231579 1.011537 0.9953132 9.066391

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

100x100 double 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]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3135529 167.5    5709258 305.0  5709258 305.0
Vcells 5793138  44.2   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMeans2_X_S = colMeans2(X_S, na.rm = FALSE), `colMeans2(X, rows, cols)` = colMeans2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMeans2(X[rows, cols])` = colMeans2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3135523 167.5    5709258 305.0  5709258 305.0
Vcells 5803221  44.3   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMeans2_X_S = rowMeans2(X_S, na.rm = FALSE), `rowMeans2(X, cols, rows)` = rowMeans2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMeans2(X[cols, rows])` = rowMeans2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMeans2_X_S(), colMeans2(X, rows, cols)() and colMeans2(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 colMeans2_X_S 0.005872 0.0064425 0.0065669 0.0065555 0.0066285 0.010052
2 colMeans2(X, rows, cols) 0.007360 0.0079870 0.0083096 0.0081505 0.0083455 0.019401
3 colMeans2(X[rows, cols]) 0.021687 0.0221865 0.0231218 0.0223320 0.0226375 0.067764
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMeans2(X, rows, cols) 1.253406 1.239736 1.265392 1.243307 1.259033 1.930064
3 colMeans2(X[rows, cols]) 3.693290 3.443772 3.520977 3.406605 3.415177 6.741345

Table: Benchmarking of rowMeans2_X_S(), rowMeans2(X, cols, rows)() and rowMeans2(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 rowMeans2_X_S 0.005919 0.0064740 0.0067625 0.0066570 0.0067815 0.014183
2 rowMeans2(X, cols, rows) 0.007441 0.0079700 0.0081432 0.0081145 0.0082450 0.010104
3 rowMeans2(X[cols, rows]) 0.013215 0.0139585 0.0149644 0.0142105 0.0144640 0.061126
expr min lq mean median uq max
1 rowMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowMeans2(X, cols, rows) 1.257138 1.231078 1.204183 1.218943 1.215808 0.7124022
3 rowMeans2(X[cols, rows]) 2.232641 2.156086 2.212866 2.134670 2.132862 4.3098075

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

Table: Benchmarking of colMeans2_X_S() and rowMeans2_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
1 colMeans2_X_S 5.872 6.4425 6.56686 6.5555 6.6285 10.052
2 rowMeans2_X_S 5.919 6.4740 6.76247 6.6570 6.7815 14.183
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMeans2_X_S 1.008004 1.004889 1.029787 1.015483 1.023082 1.410963

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

1000x10 double 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]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3135741 167.5    5709258 305.0  5709258 305.0
Vcells 5794560  44.3   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMeans2_X_S = colMeans2(X_S, na.rm = FALSE), `colMeans2(X, rows, cols)` = colMeans2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMeans2(X[rows, cols])` = colMeans2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3135732 167.5    5709258 305.0  5709258 305.0
Vcells 5804638  44.3   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMeans2_X_S = rowMeans2(X_S, na.rm = FALSE), `rowMeans2(X, cols, rows)` = rowMeans2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMeans2(X[cols, rows])` = rowMeans2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMeans2_X_S(), colMeans2(X, rows, cols)() and colMeans2(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 colMeans2_X_S 0.006849 0.0070510 0.0072699 0.0071870 0.0073375 0.009987
2 colMeans2(X, rows, cols) 0.007977 0.0083060 0.0090472 0.0084335 0.0086530 0.050012
3 colMeans2(X[rows, cols]) 0.022526 0.0228485 0.0236583 0.0230470 0.0233030 0.040380
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMeans2(X, rows, cols) 1.164696 1.177989 1.244474 1.173438 1.179285 5.007710
3 colMeans2(X[rows, cols]) 3.288947 3.240462 3.254284 3.206762 3.175877 4.043256

Table: Benchmarking of rowMeans2_X_S(), rowMeans2(X, cols, rows)() and rowMeans2(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 rowMeans2_X_S 0.006955 0.0071505 0.0076115 0.0072860 0.0074295 0.036883
2 rowMeans2(X, cols, rows) 0.007956 0.0082800 0.0086619 0.0084415 0.0086805 0.022799
3 rowMeans2(X[cols, rows]) 0.015898 0.0163690 0.0169838 0.0165925 0.0168355 0.029619
expr min lq mean median uq max
1 rowMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowMeans2(X, cols, rows) 1.143925 1.157961 1.138006 1.158592 1.168383 0.6181439
3 rowMeans2(X[cols, rows]) 2.285837 2.289210 2.231342 2.277313 2.266034 0.8030529

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

Table: Benchmarking of colMeans2_X_S() and rowMeans2_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 colMeans2_X_S 6.849 7.0510 7.26990 7.187 7.3375 9.987
2 rowMeans2_X_S 6.955 7.1505 7.61149 7.286 7.4295 36.883
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMeans2_X_S 1.015477 1.014112 1.046987 1.013775 1.012538 3.693101

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

10x1000 double 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]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3135944 167.5    5709258 305.0  5709258 305.0
Vcells 5794692  44.3   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMeans2_X_S = colMeans2(X_S, na.rm = FALSE), `colMeans2(X, rows, cols)` = colMeans2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMeans2(X[rows, cols])` = colMeans2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3135938 167.5    5709258 305.0  5709258 305.0
Vcells 5804775  44.3   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMeans2_X_S = rowMeans2(X_S, na.rm = FALSE), `rowMeans2(X, cols, rows)` = rowMeans2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMeans2(X[cols, rows])` = rowMeans2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMeans2_X_S(), colMeans2(X, rows, cols)() and colMeans2(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 colMeans2_X_S 0.007723 0.007972 0.0081978 0.0080790 0.0082330 0.012079
2 colMeans2(X, rows, cols) 0.010596 0.010898 0.0116180 0.0110600 0.0112635 0.060178
3 colMeans2(X[rows, cols]) 0.017175 0.017608 0.0183274 0.0178085 0.0180270 0.031155
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMeans2(X, rows, cols) 1.372006 1.367035 1.417200 1.368981 1.368092 4.982035
3 colMeans2(X[rows, cols]) 2.223877 2.208731 2.235649 2.204295 2.189603 2.579270

Table: Benchmarking of rowMeans2_X_S(), rowMeans2(X, cols, rows)() and rowMeans2(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 rowMeans2_X_S 0.007709 0.0079320 0.0082596 0.0080340 0.008173 0.023288
2 rowMeans2(X, cols, rows) 0.009782 0.0101190 0.0103566 0.0103075 0.010485 0.011927
3 rowMeans2(X[cols, rows]) 0.015188 0.0157655 0.0162749 0.0159710 0.016128 0.033182
expr min lq mean median uq max
1 rowMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowMeans2(X, cols, rows) 1.268906 1.275719 1.253891 1.282985 1.282883 0.5121522
3 rowMeans2(X[cols, rows]) 1.970165 1.987582 1.970422 1.987926 1.973327 1.4248540

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

Table: Benchmarking of colMeans2_X_S() and rowMeans2_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 rowMeans2_X_S 7.709 7.932 8.25960 8.034 8.173 23.288
1 colMeans2_X_S 7.723 7.972 8.19782 8.079 8.233 12.079
expr min lq mean median uq max
2 rowMeans2_X_S 1.000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
1 colMeans2_X_S 1.001816 1.005043 0.9925202 1.005601 1.007341 0.5186791

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

100x1000 double 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]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3136143 167.5    5709258 305.0  5709258 305.0
Vcells 5840147  44.6   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMeans2_X_S = colMeans2(X_S, na.rm = FALSE), `colMeans2(X, rows, cols)` = colMeans2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMeans2(X[rows, cols])` = colMeans2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3136137 167.5    5709258 305.0  5709258 305.0
Vcells 5940230  45.4   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMeans2_X_S = rowMeans2(X_S, na.rm = FALSE), `rowMeans2(X, cols, rows)` = rowMeans2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMeans2(X[cols, rows])` = rowMeans2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMeans2_X_S(), colMeans2(X, rows, cols)() and colMeans2(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 colMeans2_X_S 0.049093 0.0495460 0.0501448 0.0497405 0.0501215 0.062054
2 colMeans2(X, rows, cols) 0.067140 0.0675770 0.0712509 0.0678340 0.0680755 0.247151
3 colMeans2(X[rows, cols]) 0.196305 0.1978025 0.2038208 0.1988080 0.2003185 0.516251
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMeans2(X, rows, cols) 1.367608 1.363924 1.420903 1.363758 1.358210 3.982838
3 colMeans2(X[rows, cols]) 3.998635 3.992300 4.064645 3.996904 3.996658 8.319383

Table: Benchmarking of rowMeans2_X_S(), rowMeans2(X, cols, rows)() and rowMeans2(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 rowMeans2_X_S 0.051898 0.0523625 0.0549039 0.0526590 0.053032 0.152804
2 rowMeans2(X, cols, rows) 0.089185 0.0895640 0.0907285 0.0897950 0.090092 0.144052
3 rowMeans2(X[cols, rows]) 0.122574 0.1287530 0.1354444 0.1316945 0.137083 0.259074
expr min lq mean median uq max
1 rowMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMeans2(X, cols, rows) 1.718467 1.710461 1.652496 1.705217 1.698823 0.942724
3 rowMeans2(X[cols, rows]) 2.361825 2.458878 2.466937 2.500892 2.584911 1.695466

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

Table: Benchmarking of colMeans2_X_S() and rowMeans2_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 colMeans2_X_S 49.093 49.5460 50.14479 49.7405 50.1215 62.054
2 rowMeans2_X_S 51.898 52.3625 54.90390 52.6590 53.0320 152.804
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMeans2_X_S 1.057136 1.056846 1.094907 1.058674 1.058069 2.462436

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

1000x100 double 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]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3136353 167.5    5709258 305.0  5709258 305.0
Vcells 5840284  44.6   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMeans2_X_S = colMeans2(X_S, na.rm = FALSE), `colMeans2(X, rows, cols)` = colMeans2(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMeans2(X[rows, cols])` = colMeans2(X[rows, cols], 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3136353 167.5    5709258 305.0  5709258 305.0
Vcells 5940377  45.4   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMeans2_X_S = rowMeans2(X_S, na.rm = FALSE), `rowMeans2(X, cols, rows)` = rowMeans2(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMeans2(X[cols, rows])` = rowMeans2(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMeans2_X_S(), colMeans2(X, rows, cols)() and colMeans2(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 colMeans2_X_S 0.052271 0.0527665 0.0535432 0.0529310 0.0535930 0.061478
2 colMeans2(X, rows, cols) 0.059460 0.0599315 0.0619651 0.0601750 0.0605510 0.106062
3 colMeans2(X[rows, cols]) 0.119594 0.1202450 0.1292758 0.1211125 0.1230175 0.405650
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMeans2(X, rows, cols) 1.137533 1.135787 1.157292 1.136857 1.129830 1.725202
3 colMeans2(X[rows, cols]) 2.287961 2.278813 2.414420 2.288120 2.295402 6.598295

Table: Benchmarking of rowMeans2_X_S(), rowMeans2(X, cols, rows)() and rowMeans2(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 rowMeans2_X_S 0.053730 0.0542410 0.0551803 0.0545730 0.0548390 0.101148
2 rowMeans2(X, cols, rows) 0.086766 0.0871835 0.0875073 0.0873960 0.0876775 0.091674
3 rowMeans2(X[cols, rows]) 0.128705 0.1336225 0.1393993 0.1367735 0.1396765 0.286298
expr min lq mean median uq max
1 rowMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowMeans2(X, cols, rows) 1.614852 1.607336 1.585843 1.601451 1.598817 0.9063353
3 rowMeans2(X[cols, rows]) 2.395403 2.463496 2.526253 2.506248 2.547029 2.8304860

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

Table: Benchmarking of colMeans2_X_S() and rowMeans2_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 colMeans2_X_S 52.271 52.7665 53.54319 52.931 53.593 61.478
2 rowMeans2_X_S 53.730 54.2410 55.18028 54.573 54.839 101.148
expr min lq mean median uq max
1 colMeans2_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMeans2_X_S 1.027912 1.027944 1.030575 1.031022 1.023249 1.645271

Figure: Benchmarking of colMeans2_X_S() and rowMeans2_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 22.76 secs.

Reproducibility

To reproduce this report, do:

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

Copyright Henrik Bengtsson. Last updated on 2019-09-10 20:43:35 (-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** ⚠️