Skip to content
hb edited this page Oct 27, 2015 · 6 revisions

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), naProb = 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 (naProb > 0) 
+         X[sample(n, size = naProb * 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 616949 33.0    1168576 62.5  1168576  62.5
Vcells 828001  6.4    2720218 20.8 46816319 357.2
> colStats <- microbenchmark(colMedians = colMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2, FUN = median, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
         used (Mb) gc trigger (Mb) max used  (Mb)
Ncells 616050 33.0    1168576 62.5  1168576  62.5
Vcells 825732  6.3    2720218 20.8 46816319 357.2
> rowStats <- microbenchmark(rowMedians = rowMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1, 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
colMedians 0.021984 0.023253 0.0258943 0.0255485 0.0274035 0.079205
apply+median 0.735687 0.748920 0.7568547 0.7538160 0.7616560 0.936957
expr min lq mean median uq max
colMedians 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
apply+median 33.46466 32.20746 29.22862 29.50529 27.79411 11.82952
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
rowMedians 0.021529 0.023370 0.0260989 0.026434 0.027497 0.076376
apply+median 0.736042 0.748101 0.7570470 0.754396 0.761485 0.952070
expr min lq mean median uq max
rowMedians 1.0000 1.00000 1.00000 1.00000 1.00000 1.00000
apply+median 34.1884 32.01117 29.00685 28.53885 27.69338 12.46557
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
colMedians 21.984 23.253 25.8943 25.5485 27.4035 79.205
rowMedians 21.529 23.370 26.0989 26.4340 27.4970 76.376
expr min lq mean median uq max
colMedians 1.0000000 1.000000 1.000000 1.00000 1.000000 1.0000000
rowMedians 0.9793031 1.005032 1.007901 1.03466 1.003412 0.9642826
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 616112 33.0    1168576 62.5  1168576  62.5
Vcells 826761  6.4    2720218 20.8 46816319 357.2
> colStats <- microbenchmark(colMedians = colMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2, FUN = median, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
         used (Mb) gc trigger (Mb) max used  (Mb)
Ncells 616106 33.0    1168576 62.5  1168576  62.5
Vcells 831804  6.4    2720218 20.8 46816319 357.2
> rowStats <- microbenchmark(rowMedians = rowMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1, 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
colMedians 0.574537 0.5857375 0.6002099 0.5930225 0.6096345 0.652782
apply+median 8.153576 8.2430765 8.5735457 8.2781910 8.3878195 14.393381
expr min lq mean median uq max
colMedians 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
apply+median 14.19156 14.07299 14.28425 13.95932 13.75877 22.04929
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
rowMedians 0.579588 0.589008 0.6067315 0.6006465 0.6182435 0.707154
apply+median 8.171300 8.250465 8.5834466 8.3015185 8.4221140 14.371237
expr min lq mean median uq max
rowMedians 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
apply+median 14.09846 14.00739 14.14703 13.82097 13.62265 20.32264
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
colMedians 574.537 585.7375 600.2099 593.0225 609.6345 652.782
rowMedians 579.588 589.0080 606.7315 600.6465 618.2435 707.154
expr min lq mean median uq max
colMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
rowMedians 1.008791 1.005584 1.010866 1.012856 1.014122 1.083293
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 616146 33.0    1168576 62.5  1168576  62.5
Vcells 826996  6.4    2720218 20.8 46816319 357.2
> colStats <- microbenchmark(colMedians = colMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2, FUN = median, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
         used (Mb) gc trigger (Mb) max used  (Mb)
Ncells 616140 33.0    1168576 62.5  1168576  62.5
Vcells 832039  6.4    2720218 20.8 46816319 357.2
> rowStats <- microbenchmark(rowMedians = rowMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1, 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
colMedians 0.550664 0.563377 0.5695384 0.5681175 0.5734225 0.624810
apply+median 1.967043 1.990671 2.0527967 2.0068925 2.0313395 5.855182
expr min lq mean median uq max
colMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
apply+median 3.572129 3.533462 3.604316 3.532531 3.542483 9.37114
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
rowMedians 0.561942 0.5708775 0.575498 0.573793 0.578923 0.655044
apply+median 1.972294 2.0309610 2.080297 2.042216 2.053225 5.893092
expr min lq mean median uq max
rowMedians 1.000000 1.000000 1.000000 1.000000 1.00000 1.000000
apply+median 3.509782 3.557613 3.614777 3.559151 3.54663 8.996483
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
colMedians 550.664 563.3770 569.5384 568.1175 573.4225 624.810
rowMedians 561.942 570.8775 575.4980 573.7930 578.9230 655.044
expr min lq mean median uq max
colMedians 1.000000 1.000000 1.000000 1.00000 1.000000 1.000000
rowMedians 1.020481 1.013313 1.010464 1.00999 1.009592 1.048389
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 616183 33.0    1168576 62.5  1168576  62.5
Vcells 827569  6.4    2720218 20.8 46816319 357.2
> colStats <- microbenchmark(colMedians = colMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2, FUN = median, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
         used (Mb) gc trigger (Mb) max used  (Mb)
Ncells 616177 33.0    1168576 62.5  1168576  62.5
Vcells 832612  6.4    2720218 20.8 46816319 357.2
> rowStats <- microbenchmark(rowMedians = rowMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1, 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
colMedians 0.636473 0.647551 0.6820018 0.6964995 0.7103625 0.826486
apply+median 69.039220 69.651379 72.6058679 70.1849300 73.1370255 188.851181
expr min lq mean median uq max
colMedians 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
apply+median 108.4716 107.5612 106.4599 100.7681 102.9573 228.4989
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
rowMedians 0.639944 0.6488375 0.699716 0.685069 0.751163 0.768754
apply+median 68.803048 69.6534570 71.671152 70.155468 73.742746 87.407614
expr min lq mean median uq max
rowMedians 1.0000 1.0000 1.0000 1.0000 1.00000 1.0000
apply+median 107.5142 107.3512 102.4289 102.4064 98.17143 113.7004
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
2 rowMedians 639.944 648.8375 699.7160 685.0690 751.1630 768.754
1 colMedians 636.473 647.5510 682.0018 696.4995 710.3625 826.486
expr min lq mean median uq max
2 rowMedians 1.0000000 1.0000000 1.0000000 1.000000 1.0000000 1.000000
1 colMedians 0.9945761 0.9980172 0.9746837 1.016685 0.9456836 1.075098
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 616221 33.0    1168576 62.5  1168576  62.5
Vcells 827958  6.4    2720218 20.8 46816319 357.2
> colStats <- microbenchmark(colMedians = colMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2, FUN = median, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
         used (Mb) gc trigger (Mb) max used  (Mb)
Ncells 616215 33.0    1168576 62.5  1168576  62.5
Vcells 878001  6.7    2720218 20.8 46816319 357.2
> rowStats <- microbenchmark(rowMedians = rowMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1, 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
colMedians 5.563861 5.593872 5.670024 5.636278 5.678271 6.201692
apply+median 81.684161 82.454463 85.517435 82.977224 88.691480 101.650482
expr min lq mean median uq max
colMedians 1.0000 1.00000 1.00000 1.00000 1.00000 1.00000
apply+median 14.6812 14.74014 15.08238 14.72199 15.61945 16.39077
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
rowMedians 5.755819 5.810164 6.099968 6.254828 6.291643 6.71782
apply+median 82.532496 83.272227 87.183014 84.262033 89.086455 204.05583
expr min lq mean median uq max
rowMedians 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
apply+median 14.33897 14.33216 14.29237 13.47152 14.15949 30.37531
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
colMedians 5.563861 5.593872 5.670024 5.636278 5.678271 6.201692
rowMedians 5.755819 5.810164 6.099968 6.254828 6.291643 6.717820
expr min lq mean median uq max
colMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
rowMedians 1.034501 1.038666 1.075828 1.109744 1.108021 1.083224
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 616254 33.0    1168576 62.5  1168576  62.5
Vcells 828419  6.4    2720218 20.8 46816319 357.2
> colStats <- microbenchmark(colMedians = colMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2, FUN = median, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
         used (Mb) gc trigger (Mb) max used  (Mb)
Ncells 616248 33.0    1168576 62.5  1168576  62.5
Vcells 878462  6.8    2720218 20.8 46816319 357.2
> rowStats <- microbenchmark(rowMedians = rowMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1, 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
colMedians 5.370255 5.454843 5.485661 5.477936 5.514723 5.664002
apply+median 19.065528 19.312196 20.202206 19.513174 19.701343 23.806442
expr min lq mean median uq max
colMedians 1.000000 1.000000 1.00000 1.00000 1.000000 1.000000
apply+median 3.550209 3.540376 3.68273 3.56214 3.572499 4.203113
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
rowMedians 5.420882 5.498012 5.583049 5.560035 5.646114 5.819213
apply+median 19.180230 19.424437 20.328119 19.624817 19.797588 24.038704
expr min lq mean median uq max
rowMedians 1.000000 1.000000 1.000000 1.000000 1.00000 1.00000
apply+median 3.538212 3.532993 3.641043 3.529621 3.50641 4.13092
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
colMedians 5.370255 5.454843 5.485661 5.477936 5.514723 5.664002
rowMedians 5.420882 5.498012 5.583049 5.560035 5.646114 5.819213
expr min lq mean median uq max
colMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
rowMedians 1.009427 1.007914 1.017753 1.014987 1.023825 1.027403
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), naProb = 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 (naProb > 0) 
+         X[sample(n, size = naProb * 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 616299 33.0    1168576 62.5  1168576  62.5
Vcells 944662  7.3    2720218 20.8 46816319 357.2
> colStats <- microbenchmark(colMedians = colMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2, FUN = median, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
         used (Mb) gc trigger (Mb) max used  (Mb)
Ncells 616284 33.0    1168576 62.5  1168576  62.5
Vcells 944790  7.3    2720218 20.8 46816319 357.2
> rowStats <- microbenchmark(rowMedians = rowMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1, 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
colMedians 0.025493 0.0273185 0.0298972 0.0301370 0.0314155 0.081992
apply+median 0.754838 0.7621100 0.7697493 0.7672295 0.7727690 0.930600
expr min lq mean median uq max
colMedians 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
apply+median 29.60962 27.89721 25.74651 25.45806 24.59834 11.34989
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
rowMedians 0.025310 0.0272015 0.0301854 0.030335 0.0316195 0.079216
apply+median 0.752472 0.7638645 0.7717108 0.769256 0.7759105 0.924807
expr min lq mean median uq max
rowMedians 1.00000 1.00000 1.00000 1.00000 1.00000 1.0000
apply+median 29.73023 28.08171 25.56573 25.35869 24.53899 11.6745
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
colMedians 25.493 27.3185 29.89723 30.137 31.4155 81.992
rowMedians 25.310 27.2015 30.18536 30.335 31.6195 79.216
expr min lq mean median uq max
colMedians 1.0000000 1.0000000 1.000000 1.00000 1.000000 1.000000
rowMedians 0.9928216 0.9957172 1.009637 1.00657 1.006494 0.966143
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 616328 33.0    1168576 62.5  1168576  62.5
Vcells 944673  7.3    2720218 20.8 46816319 357.2
> colStats <- microbenchmark(colMedians = colMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2, FUN = median, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
         used (Mb) gc trigger (Mb) max used  (Mb)
Ncells 616322 33.0    1168576 62.5  1168576  62.5
Vcells 954716  7.3    2720218 20.8 46816319 357.2
> rowStats <- microbenchmark(rowMedians = rowMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1, 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
colMedians 0.97986 0.9885755 1.003982 0.9971385 1.009831 1.159057
apply+median 8.65658 8.7356830 9.074466 8.7740540 8.849899 15.014956
expr min lq mean median uq max
colMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
apply+median 8.834507 8.836637 9.038474 8.799233 8.763742 12.95446
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
rowMedians 0.982058 0.9865455 1.003638 0.9986715 1.009146 1.102595
apply+median 8.660702 8.7246820 9.166839 8.7724110 8.846168 24.131511
expr min lq mean median uq max
rowMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
apply+median 8.818931 8.843669 9.133608 8.784081 8.765999 21.88611
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
colMedians 979.860 988.5755 1003.982 997.1385 1009.831 1159.057
rowMedians 982.058 986.5455 1003.638 998.6715 1009.145 1102.595
expr min lq mean median uq max
colMedians 1.000000 1.0000000 1.0000000 1.000000 1.0000000 1.0000000
rowMedians 1.002243 0.9979465 0.9996574 1.001537 0.9993212 0.9512863
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 616362 33.0    1168576 62.5  1168576  62.5
Vcells 945444  7.3    2720218 20.8 46816319 357.2
> colStats <- microbenchmark(colMedians = colMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2, FUN = median, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
         used (Mb) gc trigger (Mb) max used  (Mb)
Ncells 616356 33.0    1168576 62.5  1168576  62.5
Vcells 955487  7.3    2720218 20.8 46816319 357.2
> rowStats <- microbenchmark(rowMedians = rowMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1, 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
colMedians 0.947704 0.952448 0.9587941 0.956655 0.962901 1.016348
apply+median 2.295113 2.308591 2.3939456 2.314060 2.321354 6.116930
expr min lq mean median uq max
colMedians 1.000000 1.00000 1.00000 1.000000 1.000000 1.000000
apply+median 2.421761 2.42385 2.49683 2.418907 2.410792 6.018539
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
rowMedians 0.953218 0.957585 0.9642135 0.9614135 0.9673075 1.054136
apply+median 2.294181 2.310779 2.3927721 2.3153960 2.3233665 6.063261
expr min lq mean median uq max
rowMedians 1.000000 1.000000 1.000000 1.000000 1.00000 1.000000
apply+median 2.406775 2.413132 2.481579 2.408325 2.40189 5.751877
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
colMedians 947.704 952.448 958.7941 956.6550 962.9010 1016.348
rowMedians 953.218 957.585 964.2135 961.4135 967.3075 1054.136
expr min lq mean median uq max
colMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
rowMedians 1.005818 1.005394 1.005652 1.004974 1.004576 1.03718
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 616399 33.0    1168576 62.5  1168576  62.5
Vcells 946368  7.3    2720218 20.8 46816319 357.2
> colStats <- microbenchmark(colMedians = colMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2, FUN = median, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
         used (Mb) gc trigger (Mb) max used  (Mb)
Ncells 616393 33.0    1168576 62.5  1168576  62.5
Vcells 956411  7.3    2720218 20.8 46816319 357.2
> rowStats <- microbenchmark(rowMedians = rowMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1, 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
colMedians 1.00256 1.006924 1.040462 1.055429 1.070299 1.095216
apply+median 70.44712 71.020255 73.836946 71.406787 74.341162 190.968668
expr min lq mean median uq max
colMedians 1.00000 1.00000 1.00000 1.00000 1.00000 1.0000
apply+median 70.26723 70.53193 70.96556 67.65665 69.45831 174.3662
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
rowMedians 1.004089 1.00774 1.069477 1.069924 1.122899 1.17808
apply+median 70.239921 70.95971 72.954504 71.520638 74.824020 88.31986
expr min lq mean median uq max
rowMedians 1.00000 1.0000 1.00000 1.00000 1.00000 1.00000
apply+median 69.95388 70.4147 68.21515 66.84647 66.63471 74.96932
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
colMedians 1.002560 1.006924 1.040462 1.055429 1.070299 1.095216
rowMedians 1.004089 1.007740 1.069477 1.069924 1.122899 1.178080
expr min lq mean median uq max
colMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
rowMedians 1.001525 1.000811 1.027887 1.013734 1.049145 1.07566
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 616437 33.0    1168576 62.5  1168576  62.5
Vcells 946394  7.3    2720218 20.8 46816319 357.2
> colStats <- microbenchmark(colMedians = colMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2, FUN = median, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used (Mb) gc trigger (Mb) max used  (Mb)
Ncells  616431   33    1168576 62.5  1168576  62.5
Vcells 1046437    8    2720218 20.8 46816319 357.2
> rowStats <- microbenchmark(rowMedians = rowMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1, 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
colMedians 9.497694 9.51868 9.608652 9.607881 9.654808 9.975026
apply+median 86.386236 87.02643 91.497260 92.055681 93.267856 205.392841
expr min lq mean median uq max
colMedians 1.000000 1.000000 1.000000 1.000000 1.00000 1.00000
apply+median 9.095496 9.142699 9.522382 9.581267 9.66025 20.59071
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
rowMedians 9.518896 9.541079 9.983978 10.25174 10.30581 10.71646
apply+median 86.613692 88.620874 92.688267 92.55178 94.39698 206.33038
expr min lq mean median uq max
rowMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
apply+median 9.099132 9.288349 9.283701 9.027908 9.159588 19.25359
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
colMedians 9.497694 9.518680 9.608652 9.607881 9.654808 9.975026
rowMedians 9.518896 9.541079 9.983978 10.251741 10.305810 10.716460
expr min lq mean median uq max
colMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
rowMedians 1.002232 1.002353 1.039061 1.067014 1.067428 1.074329
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 616470 33.0    1168576 62.5  1168576  62.5
Vcells 947507  7.3    2720218 20.8 46816319 357.2
> colStats <- microbenchmark(colMedians = colMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 2, FUN = median, 
+     na.rm = FALSE), unit = "ms")
> X <- t(X)
> gc()
          used (Mb) gc trigger (Mb) max used  (Mb)
Ncells  616464   33    1168576 62.5  1168576  62.5
Vcells 1047550    8    2720218 20.8 46816319 357.2
> rowStats <- microbenchmark(rowMedians = rowMedians(X, 
+     na.rm = FALSE), `apply+median` = apply(X, MARGIN = 1, 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
colMedians 9.21618 9.242066 9.28544 9.286769 9.317089 9.484179
apply+median 22.50194 22.604104 24.02622 22.689903 26.304582 26.716820
expr min lq mean median uq max
colMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
apply+median 2.441569 2.445785 2.587516 2.443251 2.823262 2.816988
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
rowMedians 9.379204 9.411378 9.579676 9.663805 9.716439 10.02473
apply+median 22.849876 23.021481 25.517116 23.152305 26.589968 128.81907
expr min lq mean median uq max
rowMedians 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
apply+median 2.436228 2.446133 2.663672 2.395775 2.736596 12.85012
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
colMedians 9.216180 9.242066 9.285440 9.286769 9.317089 9.484179
rowMedians 9.379204 9.411378 9.579676 9.663805 9.716439 10.024733
expr min lq mean median uq max
colMedians 1.000000 1.00000 1.000000 1.000000 1.000000 1.000000
rowMedians 1.017689 1.01832 1.031688 1.040599 1.042862 1.056995
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.2.2 Patched (2015-10-26 r69575)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
[1] C

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

other attached packages:
[1] markdown_0.7.7       microbenchmark_1.4-2 matrixStats_0.15.0  
[4] ggplot2_1.0.1        knitr_1.11           R.devices_2.13.1    
[7] R.utils_2.1.0        R.oo_1.19.0          R.methodsS3_1.7.0   

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.1      magrittr_1.5     MASS_7.3-44      munsell_0.4.2   
 [5] colorspace_1.2-6 R.cache_0.11.0   stringr_1.0.0    highr_0.5.1     
 [9] plyr_1.8.3       tools_3.2.2      grid_3.2.2       gtable_0.1.2    
[13] digest_0.6.8     R.rsp_0.20.0     reshape2_1.4.1   base64enc_0.1-3 
[17] mime_0.4         labeling_0.3     stringi_1.0-1    scales_0.3.0    
[21] proto_0.3-10    

Total processing time was 1.76 mins.

Reproducibility

To reproduce this report, do:

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

Copyright Henrik Bengtsson. Last updated on 2015-10-27 11:41:04 (-0700 UTC). Powered by RSP.

<script> var link = document.createElement('link'); link.rel = 'icon'; link.href = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAABI1BMVEUAAAAAAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8AAP8BAf4CAv0GBvkHB/gfH+AgIN8hId4iIt0kJNslJdomJtk+PsE/P8BAQL9yco10dIt1dYp2dol9fYJ/f4CAgH+Dg3yVlWqWlmmYmGeZmWacnGOdnWKenmGfn2CgoF+hoV6iol3l5Rrm5hno6Bfy8g3z8wz39wj4+Af5+Qb//wAmJPJOAAAAYXRSTlMAAQMGBwgJCgsMDiUmKD4/QFlaXF1eY2RmaGprbJ+goaWqrK2vsbu8vsTGx8jh5OXm5/Lz+vv/////////////////////////////////////////////////////////hU9TewAAATpJREFUOI29k9daAjEQhYNuUxewgBV7w4KiyFlQFBbsvRdEdt//KZzwLWy2oFf6XyU5J9/MZCaM/TNqNB6Pyt1UJZXOg8inU0qYnsyiw1YyIMtzXCiYtZpZ4KtZX6D+TTos39dton5Xps2GJuo9y3T72rIdrCsDWIoIhgm68mYLPNPBmKtrO8C57eEUyKodQwI4tLyG5gEw3DEs+AJwnoD5ti7lsN/wGxpF5Hodgw6Yft22S4DuGAaB46BBqONXQ3gIKmPgpyQ/i9htJ8nLfPUbHoUy2QhQanr1L89DaTQKZ17DCbDtPjUbp5RfRP2BDkaFbkao3cal2+4Lavei2G7Wt84H5vaDy+83R7RZU5kHaaY1cpVqtWLw1bTE/CQy7tBmhgIyoUyttsZ+b2UydOw5sh6L6V0/zl/xDYw9kI6Afx8rAAAAAElFTkSuQmCC" document.getElementsByTagName('head')[0].appendChild(link); </script>
Clone this wiki locally