colRowMedians - HenrikBengtsson/matrixStats GitHub Wiki

matrixStats: Benchmark report


colMedians() and rowMedians() benchmarks

This report benchmark the performance of colMedians() and rowMedians() against alternative methods.

Alternative methods

  • apply() + median()

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"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3148394 168.2    5709258 305.0  5709258 305.0
Vcells 6133517  46.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians = colMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2L, 
+     FUN = median, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3146917 168.1    5709258 305.0  5709258 305.0
Vcells 6129255  46.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians = rowMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1L, 
+     FUN = median, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians() and apply+median() 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 0.001423 0.0016740 0.0024066 0.0021500 0.002920 0.013546
2 apply+median 0.248046 0.2501115 0.2544108 0.2516985 0.253451 0.436424
expr min lq mean median uq max
1 colMedians 1.000 1.0000 1.0000 1.0000 1.00000 1.00000
2 apply+median 174.312 149.4095 105.7134 117.0691 86.79829 32.21792

Table: Benchmarking of rowMedians() and apply+median() 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 0.001406 0.0017075 0.0025164 0.0027120 0.002945 0.012756
2 apply+median 0.246852 0.2505395 0.2546976 0.2519685 0.253652 0.450944
expr min lq mean median uq max
1 rowMedians 1.0000 1.0000 1.0000 1.00000 1.00000 1.00000
2 apply+median 175.5704 146.7288 101.2151 92.90874 86.12971 35.35152

Figure: Benchmarking of colMedians() and apply+median() on integer+10x10 data as well as rowMedians() and apply+median() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colMedians() and rowMedians() 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 1.423 1.6740 2.40661 2.150 2.920 13.546
2 rowMedians 1.406 1.7075 2.51640 2.712 2.945 12.756
expr min lq mean median uq max
1 colMedians 1.0000000 1.000000 1.00000 1.000000 1.000000 1.0000000
2 rowMedians 0.9880534 1.020012 1.04562 1.261395 1.008562 0.9416802

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

100x100 integer matrix

> X <- data[["100x100"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3145475 168.0    5709258 305.0  5709258 305.0
Vcells 5745751  43.9   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians = colMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2L, 
+     FUN = median, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3145466 168.0    5709258 305.0  5709258 305.0
Vcells 5750789  43.9   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians = rowMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1L, 
+     FUN = median, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians() and apply+median() 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 0.109616 0.112410 0.1167811 0.115310 0.116568 0.161789
2 apply+median 2.574255 2.610474 2.7723719 2.637329 2.728289 10.863687
expr min lq mean median uq max
1 colMedians 1.0000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+median 23.4843 23.22279 23.73991 22.87164 23.40512 67.14725

Table: Benchmarking of rowMedians() and apply+median() 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 0.109995 0.111854 0.1175396 0.115371 0.116633 0.206936
2 apply+median 2.582868 2.616979 2.7824168 2.657897 2.735140 10.650263
expr min lq mean median uq max
1 rowMedians 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+median 23.48169 23.39638 23.67216 23.03782 23.45082 51.46646

Figure: Benchmarking of colMedians() and apply+median() on integer+100x100 data as well as rowMedians() and apply+median() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colMedians() and rowMedians() 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 109.616 112.410 116.7811 115.310 116.568 161.789
2 rowMedians 109.995 111.854 117.5396 115.371 116.633 206.936
expr min lq mean median uq max
1 colMedians 1.000000 1.0000000 1.000000 1.000000 1.000000 1.000000
2 rowMedians 1.003457 0.9950538 1.006496 1.000529 1.000558 1.279049

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

1000x10 integer matrix

> X <- data[["1000x10"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3146205 168.1    5709258 305.0  5709258 305.0
Vcells 5749258  43.9   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians = colMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2L, 
+     FUN = median, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3146196 168.1    5709258 305.0  5709258 305.0
Vcells 5754296  44.0   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians = rowMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1L, 
+     FUN = median, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians() and apply+median() 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 0.098588 0.1006090 0.1023026 0.102130 0.1031450 0.139008
2 apply+median 0.443335 0.4537355 0.4630561 0.460301 0.4701085 0.610789
expr min lq mean median uq max
1 colMedians 1.000000 1.00000 1.000000 1.000000 1.000000 1.000000
2 apply+median 4.496846 4.50989 4.526339 4.507011 4.557744 4.393913

Table: Benchmarking of rowMedians() and apply+median() 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 0.099118 0.1013455 0.1033351 0.1034135 0.104261 0.143447
2 apply+median 0.445403 0.4543925 0.4675050 0.4656450 0.474332 0.610581
expr min lq mean median uq max
1 rowMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 apply+median 4.493664 4.483598 4.524166 4.502749 4.549467 4.256492

Figure: Benchmarking of colMedians() and apply+median() on integer+1000x10 data as well as rowMedians() and apply+median() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colMedians() and rowMedians() 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 98.588 100.6090 102.3026 102.1300 103.145 139.008
2 rowMedians 99.118 101.3455 103.3351 103.4135 104.261 143.447
expr min lq mean median uq max
1 colMedians 1.000000 1.00000 1.000000 1.000000 1.00000 1.000000
2 rowMedians 1.005376 1.00732 1.010093 1.012567 1.01082 1.031933

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

10x1000 integer matrix

> X <- data[["10x1000"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3146394 168.1    5709258 305.0  5709258 305.0
Vcells 5749938  43.9   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians = colMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2L, 
+     FUN = median, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3146385 168.1    5709258 305.0  5709258 305.0
Vcells 5754976  44.0   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians = rowMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1L, 
+     FUN = median, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians() and apply+median() 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 0.117463 0.1231185 0.1348281 0.137208 0.1425285 0.174475
2 apply+median 23.386243 23.8971810 25.5755624 24.488757 25.7706055 38.426301
expr min lq mean median uq max
1 colMedians 1.0000 1.000 1.0000 1.0000 1.0000 1.0000
2 apply+median 199.0945 194.099 189.6902 178.4791 180.8102 220.2396

Table: Benchmarking of rowMedians() and apply+median() 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 0.118322 0.1241225 0.139761 0.1424645 0.1482465 0.181293
2 apply+median 23.323961 23.8218750 25.736911 24.6920935 25.9868975 42.304547
expr min lq mean median uq max
1 rowMedians 1.0000 1.0000 1.0000 1.000 1.0000 1.000
2 apply+median 197.1228 191.9223 184.1495 173.321 175.2952 233.349

Figure: Benchmarking of colMedians() and apply+median() on integer+10x1000 data as well as rowMedians() and apply+median() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colMedians() and rowMedians() 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 colMedians 117.463 123.1185 134.8281 137.2080 142.5285 174.475
2 rowMedians 118.322 124.1225 139.7610 142.4645 148.2465 181.293
expr min lq mean median uq max
1 colMedians 1.000000 1.000000 1.000000 1.00000 1.000000 1.000000
2 rowMedians 1.007313 1.008155 1.036586 1.03831 1.040118 1.039077

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

100x1000 integer matrix

> X <- data[["100x1000"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3146575 168.1    5709258 305.0  5709258 305.0
Vcells 5750419  43.9   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians = colMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2L, 
+     FUN = median, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3146566 168.1    5709258 305.0  5709258 305.0
Vcells 5800457  44.3   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians = rowMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1L, 
+     FUN = median, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians() and apply+median() 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 1.083893 1.096217 1.135232 1.10672 1.13207 1.424282
2 apply+median 25.685347 26.059254 28.176103 26.70994 27.97560 40.550065
expr min lq mean median uq max
1 colMedians 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+median 23.69731 23.77198 24.81969 24.13432 24.71191 28.47053

Table: Benchmarking of rowMedians() and apply+median() 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 1.098262 1.131919 1.188056 1.17516 1.187909 1.531868
2 apply+median 25.894567 26.398205 28.532177 27.38014 28.505834 39.601564
expr min lq mean median uq max
1 rowMedians 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+median 23.57777 23.32163 24.01586 23.29908 23.99665 25.85181

Figure: Benchmarking of colMedians() and apply+median() on integer+100x1000 data as well as rowMedians() and apply+median() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colMedians() and rowMedians() 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 1.083893 1.096217 1.135232 1.10672 1.132070 1.424282
2 rowMedians 1.098262 1.131919 1.188056 1.17516 1.187909 1.531868
expr min lq mean median uq max
1 colMedians 1.000000 1.000000 1.000000 1.00000 1.000000 1.000000
2 rowMedians 1.013257 1.032569 1.046531 1.06184 1.049325 1.075537

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

1000x100 integer matrix

> X <- data[["1000x100"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3146771 168.1    5709258 305.0  5709258 305.0
Vcells 5750997  43.9   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians = colMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2L, 
+     FUN = median, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3146762 168.1    5709258 305.0  5709258 305.0
Vcells 5801035  44.3   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians = rowMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1L, 
+     FUN = median, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians() and apply+median() 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 0.954607 0.9608395 0.9816954 0.968706 0.984626 1.169861
2 apply+median 4.170526 4.2111795 4.3670111 4.244028 4.313897 12.638877
expr min lq mean median uq max
1 colMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
2 apply+median 4.368841 4.382813 4.448438 4.381131 4.381254 10.80374

Table: Benchmarking of rowMedians() and apply+median() 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 0.978798 0.9875265 1.001061 0.992718 1.001716 1.176836
2 apply+median 4.191627 4.2368835 4.425128 4.274832 4.343601 13.118333
expr min lq mean median uq max
1 rowMedians 1.000000 1.0000 1.000000 1.00000 1.00000 1.00000
2 apply+median 4.282423 4.2904 4.420437 4.30619 4.33616 11.14712

Figure: Benchmarking of colMedians() and apply+median() on integer+1000x100 data as well as rowMedians() and apply+median() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colMedians() and rowMedians() 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 954.607 960.8395 981.6954 968.706 984.626 1169.861
2 rowMedians 978.798 987.5265 1001.0613 992.718 1001.716 1176.836
expr min lq mean median uq max
1 colMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMedians 1.025341 1.027775 1.019727 1.024788 1.017357 1.005962

Figure: Benchmarking of colMedians() and rowMedians() 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"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3146982 168.1    5709258 305.0  5709258 305.0
Vcells 5867406  44.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians = colMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2L, 
+     FUN = median, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3146961 168.1    5709258 305.0  5709258 305.0
Vcells 5867524  44.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians = rowMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1L, 
+     FUN = median, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians() and apply+median() 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 0.002052 0.002413 0.0033440 0.0028420 0.0040460 0.013901
2 apply+median 0.253187 0.255719 0.2623944 0.2575165 0.2596935 0.436757
expr min lq mean median uq max
1 colMedians 1.0000 1.0000 1.00000 1.00000 1.00000 1.00000
2 apply+median 123.3855 105.9755 78.46652 90.61101 64.18524 31.41911

Table: Benchmarking of rowMedians() and apply+median() 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 0.002051 0.0025470 0.0035260 0.0038125 0.004020 0.013935
2 apply+median 0.252701 0.2554865 0.2592114 0.2568135 0.258696 0.434011
expr min lq mean median uq max
1 rowMedians 1.0000 1.0000 1.00000 1.00000 1.00000 1.00000
2 apply+median 123.2087 100.3088 73.51491 67.36092 64.35224 31.14539

Figure: Benchmarking of colMedians() and apply+median() on double+10x10 data as well as rowMedians() and apply+median() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colMedians() and rowMedians() 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 2.052 2.413 3.34403 2.8420 4.046 13.901
2 rowMedians 2.051 2.547 3.52597 3.8125 4.020 13.935
expr min lq mean median uq max
1 colMedians 1.0000000 1.000000 1.000000 1.000000 1.0000000 1.000000
2 rowMedians 0.9995127 1.055532 1.054407 1.341485 0.9935739 1.002446

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

100x100 double matrix

> X <- data[["100x100"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3147157 168.1    5709258 305.0  5709258 305.0
Vcells 5867511  44.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians = colMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2L, 
+     FUN = median, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3147148 168.1    5709258 305.0  5709258 305.0
Vcells 5877549  44.9   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians = rowMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1L, 
+     FUN = median, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians() and apply+median() 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 0.175608 0.1790945 0.1883326 0.182464 0.190529 0.270138
2 apply+median 2.728487 2.7579685 2.9788384 2.830185 2.951084 12.306626
expr min lq mean median uq max
1 colMedians 1.00000 1.00000 1.0000 1.00000 1.0000 1.00000
2 apply+median 15.53737 15.39952 15.8169 15.51093 15.4889 45.55681

Table: Benchmarking of rowMedians() and apply+median() 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 0.175110 0.177632 0.1931822 0.180092 0.196236 0.27076
2 apply+median 2.687166 2.725458 3.1147334 2.814103 3.208063 12.61086
expr min lq mean median uq max
1 rowMedians 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+median 15.34559 15.34328 16.12329 15.62592 16.34798 46.57579

Figure: Benchmarking of colMedians() and apply+median() on double+100x100 data as well as rowMedians() and apply+median() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

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

expr min lq mean median uq max
2 rowMedians 175.110 177.6320 193.1822 180.092 196.236 270.760
1 colMedians 175.608 179.0945 188.3326 182.464 190.529 270.138
expr min lq mean median uq max
2 rowMedians 1.000000 1.000000 1.000000 1.000000 1.0000000 1.0000000
1 colMedians 1.002844 1.008233 0.974896 1.013171 0.9709177 0.9977028

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

1000x10 double matrix

> X <- data[["1000x10"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3147347 168.1    5709258 305.0  5709258 305.0
Vcells 5868406  44.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians = colMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2L, 
+     FUN = median, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3147338 168.1    5709258 305.0  5709258 305.0
Vcells 5878444  44.9   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians = rowMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1L, 
+     FUN = median, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians() and apply+median() 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 0.164355 0.165701 0.1676767 0.1666995 0.167651 0.196310
2 apply+median 0.564931 0.572115 0.5792054 0.5771955 0.581564 0.738975
expr min lq mean median uq max
1 colMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 apply+median 3.437261 3.452695 3.454299 3.462491 3.468897 3.764327

Table: Benchmarking of rowMedians() and apply+median() 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 0.165467 0.1670745 0.1699849 0.168743 0.1698615 0.233873
2 apply+median 0.519870 0.5268825 0.5388262 0.532013 0.5394455 0.712988
expr min lq mean median uq max
1 rowMedians 1.000000 1.000000 1.000000 1.0000 1.000000 1.000000
2 apply+median 3.141835 3.153578 3.169848 3.1528 3.175796 3.048612

Figure: Benchmarking of colMedians() and apply+median() on double+1000x10 data as well as rowMedians() and apply+median() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colMedians() and rowMedians() 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 164.355 165.7010 167.6767 166.6995 167.6510 196.310
2 rowMedians 165.467 167.0745 169.9849 168.7430 169.8615 233.873
expr min lq mean median uq max
1 colMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMedians 1.006766 1.008289 1.013766 1.012259 1.013185 1.191345

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

10x1000 double matrix

> X <- data[["10x1000"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3147536 168.1    5709258 305.0  5709258 305.0
Vcells 5869450  44.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians = colMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2L, 
+     FUN = median, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3147527 168.1    5709258 305.0  5709258 305.0
Vcells 5879488  44.9   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians = rowMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1L, 
+     FUN = median, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians() and apply+median() 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 0.187505 0.1898935 0.2009421 0.2010535 0.204783 0.269487
2 apply+median 23.604804 24.2873645 25.9720811 24.9555915 26.082657 40.187996
expr min lq mean median uq max
1 colMedians 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
2 apply+median 125.8889 127.8999 129.2516 124.1241 127.3673 149.1278

Table: Benchmarking of rowMedians() and apply+median() 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 0.187344 0.189299 0.2021045 0.2026505 0.206341 0.254486
2 apply+median 23.749928 24.189493 28.2420950 24.7616655 26.200569 275.449402
expr min lq mean median uq max
1 rowMedians 1.0000 1.0000 1.0000 1.000 1.000 1.000
2 apply+median 126.7718 127.7846 139.7401 122.189 126.977 1082.375

Figure: Benchmarking of colMedians() and apply+median() on double+10x1000 data as well as rowMedians() and apply+median() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colMedians() and rowMedians() 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 187.505 189.8935 200.9421 201.0535 204.783 269.487
2 rowMedians 187.344 189.2990 202.1045 202.6505 206.341 254.486
expr min lq mean median uq max
1 colMedians 1.0000000 1.0000000 1.000000 1.000000 1.000000 1.000000
2 rowMedians 0.9991414 0.9968693 1.005785 1.007943 1.007608 0.944335

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

100x1000 double matrix

> X <- data[["100x1000"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3147717 168.2    5709258 305.0  5709258 305.0
Vcells 5869568  44.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians = colMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2L, 
+     FUN = median, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3147708 168.2    5709258 305.0  5709258 305.0
Vcells 5969606  45.6   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians = rowMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1L, 
+     FUN = median, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians() and apply+median() 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 1.717125 1.74174 1.796505 1.757344 1.794398 2.231628
2 apply+median 27.228123 27.45129 29.604891 28.156392 29.288622 41.757641
expr min lq mean median uq max
1 colMedians 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+median 15.85681 15.76084 16.47916 16.02213 16.32225 18.71174

Table: Benchmarking of rowMedians() and apply+median() 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 1.728971 1.783241 1.870608 1.862461 1.910765 2.329959
2 apply+median 26.920152 27.245376 29.599800 28.054550 29.389402 54.122493
expr min lq mean median uq max
1 rowMedians 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+median 15.57004 15.27858 15.82362 15.06316 15.38096 23.22895

Figure: Benchmarking of colMedians() and apply+median() on double+100x1000 data as well as rowMedians() and apply+median() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colMedians() and rowMedians() 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 1.717125 1.741740 1.796505 1.757344 1.794398 2.231628
2 rowMedians 1.728971 1.783241 1.870608 1.862461 1.910765 2.329959
expr min lq mean median uq max
1 colMedians 1.000000 1.000000 1.000000 1.000000 1.00000 1.000000
2 rowMedians 1.006899 1.023827 1.041249 1.059816 1.06485 1.044062

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

1000x100 double matrix

> X <- data[["1000x100"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3147913 168.2    5709258 305.0  5709258 305.0
Vcells 5870807  44.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colMedians = colMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2L, 
+     FUN = median, na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3147904 168.2    5709258 305.0  5709258 305.0
Vcells 5970845  45.6   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowMedians = rowMedians(X, na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1L, 
+     FUN = median, na.rm = FALSE), unit = "ms")

Table: Benchmarking of colMedians() and apply+median() 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 1.619787 1.641606 1.678234 1.666539 1.69203 2.062155
2 apply+median 4.969596 5.031284 5.313666 5.066277 5.13795 13.545102
expr min lq mean median uq max
1 colMedians 1.000000 1.000000 1.000000 1.000000 1.00000 1.000000
2 apply+median 3.068055 3.064855 3.166225 3.039999 3.03656 6.568421

Table: Benchmarking of rowMedians() and apply+median() 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 1.655235 1.68752 1.728076 1.711755 1.739273 2.180682
2 apply+median 5.007882 5.11950 5.400718 5.181375 5.232999 12.726529
expr min lq mean median uq max
1 rowMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 apply+median 3.025481 3.033743 3.125279 3.026936 3.008727 5.836032

Figure: Benchmarking of colMedians() and apply+median() on double+1000x100 data as well as rowMedians() and apply+median() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colMedians() and rowMedians() 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 1.619787 1.641606 1.678234 1.666539 1.692030 2.062155
2 rowMedians 1.655235 1.687520 1.728076 1.711755 1.739273 2.180682
expr min lq mean median uq max
1 colMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowMedians 1.021884 1.027969 1.029699 1.027132 1.027921 1.057477

Figure: Benchmarking of colMedians() and rowMedians() 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 49.1 secs.

Reproducibility

To reproduce this report, do:

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

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