colRowMedians_subset - HenrikBengtsson/matrixStats GitHub Wiki

matrixStats: Benchmark report


colMedians() and rowMedians() benchmarks on subsetted computation

This report benchmark the performance of colMedians() and rowMedians() 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 3144507 168.0    5709258 305.0  5709258 305.0
Vcells 6058136  46.3   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians_X_S = colMedians(X_S, na.rm = FALSE), `colMedians(X, rows, cols)` = colMedians(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMedians(X[rows, cols])` = colMedians(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 3143232 167.9    5709258 305.0  5709258 305.0
Vcells 6054716  46.2   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians_X_S = rowMedians(X_S, na.rm = FALSE), `rowMedians(X, cols, rows)` = rowMedians(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMedians(X[cols, rows])` = rowMedians(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians_X_S(), colMedians(X, rows, cols)() and colMedians(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 colMedians_X_S 0.001149 0.001189 0.0015274 0.0012160 0.0012640 0.028063
2 colMedians(X, rows, cols) 0.001316 0.001361 0.0014472 0.0013805 0.0014735 0.003297
3 colMedians(X[rows, cols]) 0.001647 0.001801 0.0020915 0.0019390 0.0020350 0.009868
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 colMedians(X, rows, cols) 1.145344 1.144659 0.947468 1.135280 1.165744 0.1174857
3 colMedians(X[rows, cols]) 1.433420 1.514718 1.369276 1.594572 1.609968 0.3516374

Table: Benchmarking of rowMedians_X_S(), rowMedians(X, cols, rows)() and rowMedians(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 rowMedians_X_S 0.001157 0.0011925 0.0012899 0.0012320 0.0013390 0.003571
2 rowMedians(X, cols, rows) 0.001319 0.0013680 0.0017177 0.0013925 0.0014625 0.029867
3 rowMedians(X[cols, rows]) 0.001653 0.0018205 0.0020435 0.0019205 0.0020485 0.007752
expr min lq mean median uq max
1 rowMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMedians(X, cols, rows) 1.140017 1.147170 1.331617 1.130276 1.092233 8.363764
3 rowMedians(X[cols, rows]) 1.428695 1.526625 1.584176 1.558847 1.529873 2.170821

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

Table: Benchmarking of colMedians_X_S() and rowMedians_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
1 colMedians_X_S 1.149 1.1890 1.52745 1.216 1.264 28.063
2 rowMedians_X_S 1.157 1.1925 1.28992 1.232 1.339 3.571
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
2 rowMedians_X_S 1.006963 1.002944 0.8444925 1.013158 1.059335 0.1272494

Figure: Benchmarking of colMedians_X_S() and rowMedians_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 3141805 167.8    5709258 305.0  5709258 305.0
Vcells 5722913  43.7   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians_X_S = colMedians(X_S, na.rm = FALSE), `colMedians(X, rows, cols)` = colMedians(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMedians(X[rows, cols])` = colMedians(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 3141799 167.8    5709258 305.0  5709258 305.0
Vcells 5727996  43.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians_X_S = rowMedians(X_S, na.rm = FALSE), `rowMedians(X, cols, rows)` = rowMedians(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMedians(X[cols, rows])` = rowMedians(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians_X_S(), colMedians(X, rows, cols)() and colMedians(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 colMedians_X_S 0.047667 0.0489455 0.0495067 0.049259 0.0496840 0.059002
2 colMedians(X, rows, cols) 0.050012 0.0510530 0.0518520 0.051677 0.0522600 0.061308
3 colMedians(X[rows, cols]) 0.056157 0.0573060 0.0585239 0.057716 0.0584625 0.107428
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMedians(X, rows, cols) 1.049195 1.043058 1.047375 1.049087 1.051848 1.039083
3 colMedians(X[rows, cols]) 1.178111 1.170812 1.182141 1.171684 1.176687 1.820752

Table: Benchmarking of rowMedians_X_S(), rowMedians(X, cols, rows)() and rowMedians(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 rowMedians_X_S 0.047473 0.0489855 0.0496492 0.0493975 0.0499180 0.062526
2 rowMedians(X, cols, rows) 0.050069 0.0508580 0.0515026 0.0514535 0.0518740 0.055714
3 rowMedians(X[cols, rows]) 0.055391 0.0570665 0.0583761 0.0575520 0.0580205 0.113789
expr min lq mean median uq max
1 rowMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowMedians(X, cols, rows) 1.054684 1.038226 1.037330 1.041621 1.039184 0.8910533
3 rowMedians(X[cols, rows]) 1.166789 1.164967 1.175771 1.165079 1.162316 1.8198669

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

Table: Benchmarking of colMedians_X_S() and rowMedians_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 colMedians_X_S 47.667 48.9455 49.50669 49.2590 49.684 59.002
2 rowMedians_X_S 47.473 48.9855 49.64924 49.3975 49.918 62.526
expr min lq mean median uq max
1 colMedians_X_S 1.0000000 1.000000 1.000000 1.000000 1.00000 1.000000
2 rowMedians_X_S 0.9959301 1.000817 1.002879 1.002812 1.00471 1.059727

Figure: Benchmarking of colMedians_X_S() and rowMedians_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 3142560 167.9    5709258 305.0  5709258 305.0
Vcells 5726981  43.7   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians_X_S = colMedians(X_S, na.rm = FALSE), `colMedians(X, rows, cols)` = colMedians(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMedians(X[rows, cols])` = colMedians(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 3142551 167.9    5709258 305.0  5709258 305.0
Vcells 5732059  43.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians_X_S = rowMedians(X_S, na.rm = FALSE), `rowMedians(X, cols, rows)` = rowMedians(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMedians(X[cols, rows])` = rowMedians(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians_X_S(), colMedians(X, rows, cols)() and colMedians(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 colMedians_X_S 0.033378 0.0343820 0.0348537 0.0346775 0.0350340 0.044493
2 colMedians(X, rows, cols) 0.035290 0.0364185 0.0371229 0.0367450 0.0372535 0.066016
3 colMedians(X[rows, cols]) 0.041412 0.0424550 0.0431284 0.0426915 0.0432365 0.055299
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMedians(X, rows, cols) 1.057283 1.059232 1.065107 1.059621 1.063353 1.483739
3 colMedians(X[rows, cols]) 1.240698 1.234803 1.237412 1.231101 1.234130 1.242870

Table: Benchmarking of rowMedians_X_S(), rowMedians(X, cols, rows)() and rowMedians(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 rowMedians_X_S 0.033378 0.0346310 0.0367103 0.0351095 0.0360145 0.078410
2 rowMedians(X, cols, rows) 0.035982 0.0370360 0.0399102 0.0375655 0.0383780 0.078175
3 rowMedians(X[cols, rows]) 0.042987 0.0437935 0.0466722 0.0442830 0.0451990 0.072242
expr min lq mean median uq max
1 rowMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowMedians(X, cols, rows) 1.078016 1.069446 1.087166 1.069953 1.065626 0.9970029
3 rowMedians(X[cols, rows]) 1.287884 1.264575 1.271365 1.261283 1.255022 0.9213366

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

Table: Benchmarking of colMedians_X_S() and rowMedians_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 colMedians_X_S 33.378 34.382 34.85371 34.6775 35.0340 44.493
2 rowMedians_X_S 33.378 34.631 36.71028 35.1095 36.0145 78.410
expr min lq mean median uq max
1 colMedians_X_S 1 1.000000 1.000000 1.000000 1.000000 1.0000
2 rowMedians_X_S 1 1.007242 1.053268 1.012458 1.027987 1.7623

Figure: Benchmarking of colMedians_X_S() and rowMedians_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 3142766 167.9    5709258 305.0  5709258 305.0
Vcells 5727864  43.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians_X_S = colMedians(X_S, na.rm = FALSE), `colMedians(X, rows, cols)` = colMedians(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMedians(X[rows, cols])` = colMedians(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 3142757 167.9    5709258 305.0  5709258 305.0
Vcells 5732942  43.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians_X_S = rowMedians(X_S, na.rm = FALSE), `rowMedians(X, cols, rows)` = rowMedians(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMedians(X[cols, rows])` = rowMedians(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians_X_S(), colMedians(X, rows, cols)() and colMedians(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 colMedians_X_S 0.036380 0.0381620 0.0396042 0.0394765 0.0408635 0.047333
2 colMedians(X, rows, cols) 0.041226 0.0434185 0.0453140 0.0444740 0.0458345 0.092878
3 colMedians(X[rows, cols]) 0.045252 0.0475475 0.0488529 0.0487825 0.0501315 0.061149
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMedians(X, rows, cols) 1.133205 1.137742 1.144171 1.126594 1.121649 1.962225
3 colMedians(X[rows, cols]) 1.243870 1.245938 1.233528 1.235735 1.226804 1.291889

Table: Benchmarking of rowMedians_X_S(), rowMedians(X, cols, rows)() and rowMedians(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 rowMedians_X_S 0.036450 0.038207 0.0399224 0.039475 0.0405905 0.077928
2 rowMedians(X, cols, rows) 0.039683 0.043051 0.0440029 0.044060 0.0450445 0.048454
3 rowMedians(X[cols, rows]) 0.044125 0.046707 0.0478617 0.047529 0.0486975 0.066379
expr min lq mean median uq max
1 rowMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowMedians(X, cols, rows) 1.088697 1.126783 1.102209 1.116149 1.109730 0.6217791
3 rowMedians(X[cols, rows]) 1.210562 1.222472 1.198867 1.204028 1.199726 0.8517991

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

Table: Benchmarking of colMedians_X_S() and rowMedians_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 rowMedians_X_S 36.45 38.207 39.92242 39.4750 40.5905 77.928
1 colMedians_X_S 36.38 38.162 39.60422 39.4765 40.8635 47.333
expr min lq mean median uq max
2 rowMedians_X_S 1.0000000 1.0000000 1.0000000 1.000000 1.000000 1.000000
1 colMedians_X_S 0.9980796 0.9988222 0.9920295 1.000038 1.006726 0.607394

Figure: Benchmarking of colMedians_X_S() and rowMedians_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 3142965 167.9    5709258 305.0  5709258 305.0
Vcells 5750532  43.9   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians_X_S = colMedians(X_S, na.rm = FALSE), `colMedians(X, rows, cols)` = colMedians(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMedians(X[rows, cols])` = colMedians(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 3142956 167.9    5709258 305.0  5709258 305.0
Vcells 5800610  44.3   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians_X_S = rowMedians(X_S, na.rm = FALSE), `rowMedians(X, cols, rows)` = rowMedians(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMedians(X[cols, rows])` = rowMedians(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians_X_S(), colMedians(X, rows, cols)() and colMedians(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 colMedians_X_S 0.551522 0.5533995 0.5551663 0.554339 0.5555935 0.602624
2 colMedians(X, rows, cols) 0.570874 0.5731625 0.5753260 0.574361 0.5752630 0.646639
3 colMedians(X[rows, cols]) 0.624087 0.6271425 0.6285843 0.628093 0.6294730 0.651826
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMedians(X, rows, cols) 1.035088 1.035712 1.036313 1.036119 1.035403 1.073039
3 colMedians(X[rows, cols]) 1.131572 1.133255 1.132245 1.133048 1.132974 1.081646

Table: Benchmarking of rowMedians_X_S(), rowMedians(X, cols, rows)() and rowMedians(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 rowMedians_X_S 0.553368 0.5559435 0.5584355 0.5565935 0.5579010 0.621667
2 rowMedians(X, cols, rows) 0.583552 0.5858350 0.5875489 0.5866875 0.5882505 0.614171
3 rowMedians(X[cols, rows]) 0.618907 0.6210605 0.6246258 0.6228175 0.6243220 0.689644
expr min lq mean median uq max
1 rowMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowMedians(X, cols, rows) 1.054546 1.053767 1.052134 1.054068 1.054399 0.9879421
3 rowMedians(X[cols, rows]) 1.118437 1.117129 1.118528 1.118981 1.119055 1.1093463

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

Table: Benchmarking of colMedians_X_S() and rowMedians_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 colMedians_X_S 551.522 553.3995 555.1663 554.3390 555.5935 602.624
2 rowMedians_X_S 553.368 555.9435 558.4355 556.5935 557.9010 621.667
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000
2 rowMedians_X_S 1.003347 1.004597 1.005889 1.004067 1.004153 1.0316

Figure: Benchmarking of colMedians_X_S() and rowMedians_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 3143181 167.9    5709258 305.0  5709258 305.0
Vcells 5751331  43.9   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians_X_S = colMedians(X_S, na.rm = FALSE), `colMedians(X, rows, cols)` = colMedians(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMedians(X[rows, cols])` = colMedians(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 3143172 167.9    5709258 305.0  5709258 305.0
Vcells 5801409  44.3   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians_X_S = rowMedians(X_S, na.rm = FALSE), `rowMedians(X, cols, rows)` = rowMedians(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMedians(X[cols, rows])` = rowMedians(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians_X_S(), colMedians(X, rows, cols)() and colMedians(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 colMedians_X_S 0.481554 0.4828520 0.4842118 0.4836605 0.4847415 0.503828
2 colMedians(X, rows, cols) 0.495361 0.4968905 0.4980478 0.4977890 0.4988960 0.504501
3 colMedians(X[rows, cols]) 0.545325 0.5473575 0.5497219 0.5482035 0.5497545 0.643403
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMedians(X, rows, cols) 1.028672 1.029074 1.028574 1.029212 1.029200 1.001336
3 colMedians(X[rows, cols]) 1.132427 1.133593 1.135292 1.133447 1.134119 1.277029

Table: Benchmarking of rowMedians_X_S(), rowMedians(X, cols, rows)() and rowMedians(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 rowMedians_X_S 0.492583 0.494789 0.4974845 0.496073 0.4982500 0.572607
2 rowMedians(X, cols, rows) 0.516114 0.518615 0.5233134 0.519426 0.5207715 0.660942
3 rowMedians(X[cols, rows]) 0.563463 0.567259 0.5769345 0.569538 0.5732690 0.908084
expr min lq mean median uq max
1 rowMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMedians(X, cols, rows) 1.047771 1.048154 1.051919 1.047076 1.045201 1.154268
3 rowMedians(X[cols, rows]) 1.143895 1.146467 1.159703 1.148093 1.150565 1.585876

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

Table: Benchmarking of colMedians_X_S() and rowMedians_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 colMedians_X_S 481.554 482.852 484.2118 483.6605 484.7415 503.828
2 rowMedians_X_S 492.583 494.789 497.4845 496.0730 498.2500 572.607
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMedians_X_S 1.022903 1.024722 1.027411 1.025664 1.027867 1.136513

Figure: Benchmarking of colMedians_X_S() and rowMedians_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 3143399 167.9    5709258 305.0  5709258 305.0
Vcells 5842448  44.6   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians_X_S = colMedians(X_S, na.rm = FALSE), `colMedians(X, rows, cols)` = colMedians(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMedians(X[rows, cols])` = colMedians(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 3143381 167.9    5709258 305.0  5709258 305.0
Vcells 5842611  44.6   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians_X_S = rowMedians(X_S, na.rm = FALSE), `rowMedians(X, cols, rows)` = rowMedians(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMedians(X[cols, rows])` = rowMedians(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians_X_S(), colMedians(X, rows, cols)() and colMedians(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 colMedians_X_S 0.001349 0.0013760 0.0017320 0.0014090 0.0015340 0.023687
2 colMedians(X, rows, cols) 0.001511 0.0015630 0.0017252 0.0015885 0.0016965 0.006934
3 colMedians(X[rows, cols]) 0.001982 0.0022165 0.0024541 0.0022980 0.0024255 0.012783
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
2 colMedians(X, rows, cols) 1.120089 1.135901 0.9960912 1.127395 1.105932 0.2927344
3 colMedians(X[rows, cols]) 1.469237 1.610828 1.4169308 1.630944 1.581160 0.5396631

Table: Benchmarking of rowMedians_X_S(), rowMedians(X, cols, rows)() and rowMedians(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 rowMedians_X_S 0.001342 0.001376 0.0015028 0.0014180 0.0015715 0.003560
2 rowMedians(X, cols, rows) 0.001485 0.001556 0.0019440 0.0015845 0.0016875 0.032230
3 rowMedians(X[cols, rows]) 0.001853 0.002102 0.0022875 0.0021655 0.0023025 0.008071
expr min lq mean median uq max
1 rowMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMedians(X, cols, rows) 1.106557 1.130814 1.293609 1.117419 1.073815 9.053371
3 rowMedians(X[cols, rows]) 1.380775 1.527616 1.522172 1.527151 1.465161 2.267135

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

Table: Benchmarking of colMedians_X_S() and rowMedians_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
1 colMedians_X_S 1.349 1.376 1.73199 1.409 1.5340 23.687
2 rowMedians_X_S 1.342 1.376 1.50278 1.418 1.5715 3.560
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1 1.0000000 1.000000 1.000000 1.0000000
2 rowMedians_X_S 0.994811 1 0.8676609 1.006387 1.024446 0.1502934

Figure: Benchmarking of colMedians_X_S() and rowMedians_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 3143598 167.9    5709258 305.0  5709258 305.0
Vcells 5848412  44.7   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians_X_S = colMedians(X_S, na.rm = FALSE), `colMedians(X, rows, cols)` = colMedians(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMedians(X[rows, cols])` = colMedians(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 3143592 167.9    5709258 305.0  5709258 305.0
Vcells 5858495  44.7   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians_X_S = rowMedians(X_S, na.rm = FALSE), `rowMedians(X, cols, rows)` = rowMedians(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMedians(X[cols, rows])` = rowMedians(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians_X_S(), colMedians(X, rows, cols)() and colMedians(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 colMedians_X_S 0.085388 0.0860420 0.0863964 0.0862540 0.0864435 0.092971
2 colMedians(X, rows, cols) 0.087565 0.0881975 0.0887758 0.0884505 0.0887785 0.105198
3 colMedians(X[rows, cols]) 0.101302 0.1019825 0.1031859 0.1022005 0.1027190 0.158396
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMedians(X, rows, cols) 1.025495 1.025052 1.027541 1.025465 1.027012 1.131514
3 colMedians(X[rows, cols]) 1.186373 1.185264 1.194331 1.184878 1.188279 1.703714

Table: Benchmarking of rowMedians_X_S(), rowMedians(X, cols, rows)() and rowMedians(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 rowMedians_X_S 0.085229 0.0861610 0.0870892 0.0865215 0.0869595 0.097032
2 rowMedians(X, cols, rows) 0.087775 0.0882475 0.0893708 0.0885260 0.0889975 0.108774
3 rowMedians(X[cols, rows]) 0.093274 0.0938740 0.0952150 0.0942530 0.0947275 0.147012
expr min lq mean median uq max
1 rowMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMedians(X, cols, rows) 1.029872 1.024216 1.026198 1.023168 1.023436 1.121012
3 rowMedians(X[cols, rows]) 1.094393 1.089519 1.093304 1.089359 1.089329 1.515088

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

Table: Benchmarking of colMedians_X_S() and rowMedians_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 colMedians_X_S 85.388 86.042 86.39642 86.2540 86.4435 92.971
2 rowMedians_X_S 85.229 86.161 87.08921 86.5215 86.9595 97.032
expr min lq mean median uq max
1 colMedians_X_S 1.0000000 1.000000 1.000000 1.000000 1.000000 1.00000
2 rowMedians_X_S 0.9981379 1.001383 1.008019 1.003101 1.005969 1.04368

Figure: Benchmarking of colMedians_X_S() and rowMedians_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 3143810 167.9    5709258 305.0  5709258 305.0
Vcells 5849857  44.7   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians_X_S = colMedians(X_S, na.rm = FALSE), `colMedians(X, rows, cols)` = colMedians(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMedians(X[rows, cols])` = colMedians(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 3143801 167.9    5709258 305.0  5709258 305.0
Vcells 5859935  44.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians_X_S = rowMedians(X_S, na.rm = FALSE), `rowMedians(X, cols, rows)` = rowMedians(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMedians(X[cols, rows])` = rowMedians(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians_X_S(), colMedians(X, rows, cols)() and colMedians(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 colMedians_X_S 0.074949 0.0757145 0.0798286 0.076534 0.0783235 0.134454
2 colMedians(X, rows, cols) 0.077416 0.0781150 0.0824540 0.078691 0.0806650 0.146220
3 colMedians(X[rows, cols]) 0.090740 0.0920850 0.0987415 0.092853 0.0943265 0.194842
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMedians(X, rows, cols) 1.032916 1.031705 1.032889 1.028184 1.029895 1.087509
3 colMedians(X[rows, cols]) 1.210690 1.216214 1.236918 1.213226 1.204319 1.449135

Table: Benchmarking of rowMedians_X_S(), rowMedians(X, cols, rows)() and rowMedians(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 rowMedians_X_S 0.076189 0.0766055 0.0779592 0.0769240 0.0786510 0.109868
2 rowMedians(X, cols, rows) 0.078286 0.0790835 0.0802436 0.0796785 0.0811865 0.094396
3 rowMedians(X[cols, rows]) 0.085653 0.0863545 0.0877400 0.0870785 0.0885220 0.097734
expr min lq mean median uq max
1 rowMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowMedians(X, cols, rows) 1.027524 1.032347 1.029302 1.035808 1.032237 0.8591765
3 rowMedians(X[cols, rows]) 1.124217 1.127262 1.125460 1.132007 1.125504 0.8895584

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

Table: Benchmarking of colMedians_X_S() and rowMedians_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 colMedians_X_S 74.949 75.7145 79.82861 76.534 78.3235 134.454
2 rowMedians_X_S 76.189 76.6055 77.95923 76.924 78.6510 109.868
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
2 rowMedians_X_S 1.016545 1.011768 0.9765826 1.005096 1.004181 0.8171419

Figure: Benchmarking of colMedians_X_S() and rowMedians_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 3144016 168.0    5709258 305.0  5709258 305.0
Vcells 5849994  44.7   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians_X_S = colMedians(X_S, na.rm = FALSE), `colMedians(X, rows, cols)` = colMedians(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMedians(X[rows, cols])` = colMedians(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 3144007 168.0    5709258 305.0  5709258 305.0
Vcells 5860072  44.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians_X_S = rowMedians(X_S, na.rm = FALSE), `rowMedians(X, cols, rows)` = rowMedians(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMedians(X[cols, rows])` = rowMedians(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians_X_S(), colMedians(X, rows, cols)() and colMedians(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 colMedians_X_S 0.067270 0.0679735 0.0688126 0.0685890 0.069349 0.075206
2 colMedians(X, rows, cols) 0.070809 0.0722080 0.0737420 0.0731680 0.073613 0.121532
3 colMedians(X[rows, cols]) 0.076863 0.0778010 0.0787147 0.0782405 0.078900 0.092896
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colMedians(X, rows, cols) 1.052609 1.062296 1.071636 1.066760 1.061486 1.615988
3 colMedians(X[rows, cols]) 1.142604 1.144578 1.143900 1.140715 1.137724 1.235221

Table: Benchmarking of rowMedians_X_S(), rowMedians(X, cols, rows)() and rowMedians(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 rowMedians_X_S 0.067203 0.0681190 0.0692430 0.068694 0.0694205 0.102883
2 rowMedians(X, cols, rows) 0.070095 0.0712345 0.0721646 0.072028 0.0724085 0.089288
3 rowMedians(X[cols, rows]) 0.075122 0.0764265 0.0776169 0.077048 0.0773895 0.100846
expr min lq mean median uq max
1 rowMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowMedians(X, cols, rows) 1.043034 1.045736 1.042193 1.048534 1.043042 0.8678596
3 rowMedians(X[cols, rows]) 1.117837 1.121956 1.120934 1.121612 1.114793 0.9802008

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

Table: Benchmarking of colMedians_X_S() and rowMedians_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
1 colMedians_X_S 67.270 67.9735 68.81259 68.589 69.3490 75.206
2 rowMedians_X_S 67.203 68.1190 69.24302 68.694 69.4205 102.883
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMedians_X_S 0.999004 1.002141 1.006255 1.001531 1.001031 1.368016

Figure: Benchmarking of colMedians_X_S() and rowMedians_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 3144215  168    5709258 305.0  5709258 305.0
Vcells 5895472   45   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians_X_S = colMedians(X_S, na.rm = FALSE), `colMedians(X, rows, cols)` = colMedians(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMedians(X[rows, cols])` = colMedians(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 3144206 168.0    5709258 305.0  5709258 305.0
Vcells 5995550  45.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians_X_S = rowMedians(X_S, na.rm = FALSE), `rowMedians(X, cols, rows)` = rowMedians(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMedians(X[cols, rows])` = rowMedians(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians_X_S(), colMedians(X, rows, cols)() and colMedians(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 colMedians_X_S 0.860940 0.8627075 0.8645793 0.8634910 0.8650695 0.900853
2 colMedians(X, rows, cols) 0.883786 0.8860305 0.8922802 0.8867275 0.8880535 0.991335
3 colMedians(X[rows, cols]) 1.009132 1.0115570 1.0295491 1.0128095 1.0153515 2.127851
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
2 colMedians(X, rows, cols) 1.026536 1.027035 1.032040 1.026910 1.026569 1.10044
3 colMedians(X[rows, cols]) 1.172128 1.172538 1.190809 1.172924 1.173723 2.36204

Table: Benchmarking of rowMedians_X_S(), rowMedians(X, cols, rows)() and rowMedians(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 rowMedians_X_S 0.864782 0.8669990 0.8816675 0.8679760 0.8710560 1.409143
2 rowMedians(X, cols, rows) 0.907987 0.9101955 0.9178074 0.9113740 0.9124870 1.261388
3 rowMedians(X[cols, rows]) 0.937342 0.9469895 0.9573683 0.9504025 0.9558485 1.173212
expr min lq mean median uq max
1 rowMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowMedians(X, cols, rows) 1.049961 1.049823 1.040990 1.049999 1.047564 0.8951455
3 rowMedians(X[cols, rows]) 1.083905 1.092261 1.085861 1.094964 1.097344 0.8325713

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

Table: Benchmarking of colMedians_X_S() and rowMedians_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 colMedians_X_S 860.940 862.7075 864.5793 863.491 865.0695 900.853
2 rowMedians_X_S 864.782 866.9990 881.6675 867.976 871.0560 1409.143
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.00000 1.000000
2 rowMedians_X_S 1.004463 1.004975 1.019765 1.005194 1.00692 1.564232

Figure: Benchmarking of colMedians_X_S() and rowMedians_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 3144431  168    5709258 305.0  5709258 305.0
Vcells 5895619   45   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians_X_S = colMedians(X_S, na.rm = FALSE), `colMedians(X, rows, cols)` = colMedians(X, 
+     rows = rows, cols = cols, na.rm = FALSE), `colMedians(X[rows, cols])` = colMedians(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 3144422 168.0    5709258 305.0  5709258 305.0
Vcells 5995697  45.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians_X_S = rowMedians(X_S, na.rm = FALSE), `rowMedians(X, cols, rows)` = rowMedians(X, 
+     rows = cols, cols = rows, na.rm = FALSE), `rowMedians(X[cols, rows])` = rowMedians(X[cols, rows], 
+     na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians_X_S(), colMedians(X, rows, cols)() and colMedians(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 colMedians_X_S 0.801808 0.8047815 0.8117196 0.806619 0.8116600 0.859881
2 colMedians(X, rows, cols) 0.821630 0.8231540 0.8379777 0.824381 0.8363015 1.438840
3 colMedians(X[rows, cols]) 0.874158 0.8768455 0.8973643 0.880392 0.8899950 1.278850
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.00000 1.000000 1.000000
2 colMedians(X, rows, cols) 1.024722 1.022829 1.032349 1.02202 1.030359 1.673301
3 colMedians(X[rows, cols]) 1.090234 1.089545 1.105510 1.09146 1.096512 1.487241

Table: Benchmarking of rowMedians_X_S(), rowMedians(X, cols, rows)() and rowMedians(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 rowMedians_X_S 0.815828 0.8178225 0.8281364 0.8197490 0.831868 0.940832
2 rowMedians(X, cols, rows) 0.852303 0.8542420 0.8684241 0.8556330 0.867120 1.145397
3 rowMedians(X[cols, rows]) 0.893871 0.9018045 0.9235859 0.9062475 0.917550 1.464133
expr min lq mean median uq max
1 rowMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMedians(X, cols, rows) 1.044709 1.044532 1.048649 1.043774 1.042377 1.217430
3 rowMedians(X[cols, rows]) 1.095661 1.102690 1.115258 1.105518 1.102999 1.556211

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

Table: Benchmarking of colMedians_X_S() and rowMedians_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 colMedians_X_S 801.808 804.7815 811.7196 806.619 811.660 859.881
2 rowMedians_X_S 815.828 817.8225 828.1364 819.749 831.868 940.832
expr min lq mean median uq max
1 colMedians_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMedians_X_S 1.017486 1.016204 1.020225 1.016278 1.024897 1.094142

Figure: Benchmarking of colMedians_X_S() and rowMedians_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 24.44 secs.

Reproducibility

To reproduce this report, do:

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

Copyright Dongcan Jiang. Last updated on 2019-09-10 20:44:30 (-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** ⚠️