colRowCumprods - HenrikBengtsson/matrixStats GitHub Wiki

matrixStats: Benchmark report


colCumprods() and rowCumprods() benchmarks

This report benchmark the performance of colCumprods() and rowCumprods() against alternative methods.

Alternative methods

  • apply() + cumprod()

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, range = c(-1, 1))

Results

10x10 integer matrix

> X <- data[["10x10"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3102269 165.7    5709258 305.0  5709258 305.0
Vcells 5802882  44.3   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumprods = colCumprods(X), `apply+cumprod` = apply(X, MARGIN = 2L, 
+     FUN = cumprod), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3101198 165.7    5709258 305.0  5709258 305.0
Vcells 5799920  44.3   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumprods = rowCumprods(X), `apply+cumprod` = apply(X, MARGIN = 1L, 
+     FUN = cumprod), unit = "ms")

Table: Benchmarking of colCumprods() and apply+cumprod() 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 colCumprods 0.001008 0.0013145 0.0017749 0.001658 0.0019545 0.011696
2 apply+cumprod 0.024891 0.0259205 0.0274608 0.026259 0.0266260 0.129661
expr min lq mean median uq max
1 colCumprods 1.00000 1.0000 1.00000 1.00000 1.00000 1.00000
2 apply+cumprod 24.69345 19.7189 15.47208 15.83776 13.62292 11.08593

Table: Benchmarking of rowCumprods() and apply+cumprod() 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 rowCumprods 0.001054 0.0014595 0.0019190 0.0018890 0.0020975 0.010228
2 apply+cumprod 0.025337 0.0258825 0.0272502 0.0262315 0.0266955 0.100219
expr min lq mean median uq max
1 rowCumprods 1.0000 1.00000 1.00000 1.00000 1.00000 1.000000
2 apply+cumprod 24.0389 17.73381 14.20057 13.88645 12.72729 9.798494

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

Table: Benchmarking of colCumprods() and rowCumprods() 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 colCumprods 1.008 1.3145 1.77486 1.658 1.9545 11.696
2 rowCumprods 1.054 1.4595 1.91895 1.889 2.0975 10.228
expr min lq mean median uq max
1 colCumprods 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumprods 1.045635 1.110308 1.081184 1.139325 1.073165 0.874487

Figure: Benchmarking of colCumprods() and rowCumprods() 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 3099753 165.6    5709258 305.0  5709258 305.0
Vcells 5416321  41.4   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumprods = colCumprods(X), `apply+cumprod` = apply(X, MARGIN = 2L, 
+     FUN = cumprod), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3099747 165.6    5709258 305.0  5709258 305.0
Vcells 5421364  41.4   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumprods = rowCumprods(X), `apply+cumprod` = apply(X, MARGIN = 1L, 
+     FUN = cumprod), unit = "ms")

Table: Benchmarking of colCumprods() and apply+cumprod() 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 colCumprods 0.017370 0.0176450 0.0184143 0.0181195 0.0184245 0.044507
2 apply+cumprod 0.177153 0.1820505 0.1897528 0.1837460 0.1898095 0.356529
expr min lq mean median uq max
1 colCumprods 1.00000 1.0000 1.00000 1.00000 1.00000 1.000000
2 apply+cumprod 10.19879 10.3174 10.30462 10.14079 10.30202 8.010628

Table: Benchmarking of rowCumprods() and apply+cumprod() 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 rowCumprods 0.018164 0.0184690 0.0191332 0.0188675 0.0193355 0.027174
2 apply+cumprod 0.176977 0.1817655 0.1896042 0.1841500 0.1896660 0.341702
expr min lq mean median uq max
1 rowCumprods 1.000000 1.000000 1.000000 1.00000 1.000000 1.00000
2 apply+cumprod 9.743283 9.841654 9.909675 9.76017 9.809211 12.57459

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

Table: Benchmarking of colCumprods() and rowCumprods() 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 colCumprods 17.370 17.645 18.41434 18.1195 18.4245 44.507
2 rowCumprods 18.164 18.469 19.13324 18.8675 19.3355 27.174
expr min lq mean median uq max
1 colCumprods 1.000000 1.000000 1.00000 1.000000 1.000000 1.0000000
2 rowCumprods 1.045711 1.046699 1.03904 1.041281 1.049445 0.6105556

Figure: Benchmarking of colCumprods() and rowCumprods() 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 3100486 165.6    5709258 305.0  5709258 305.0
Vcells 5419843  41.4   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumprods = colCumprods(X), `apply+cumprod` = apply(X, MARGIN = 2L, 
+     FUN = cumprod), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3100477 165.6    5709258 305.0  5709258 305.0
Vcells 5424881  41.4   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumprods = rowCumprods(X), `apply+cumprod` = apply(X, MARGIN = 1L, 
+     FUN = cumprod), unit = "ms")

Table: Benchmarking of colCumprods() and apply+cumprod() 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 colCumprods 0.016827 0.0170745 0.0177498 0.0174820 0.0177875 0.035532
2 apply+cumprod 0.112237 0.1138930 0.1190128 0.1157075 0.1177295 0.204261
expr min lq mean median uq max
1 colCumprods 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 apply+cumprod 6.670054 6.670356 6.705038 6.618665 6.618665 5.748649

Table: Benchmarking of rowCumprods() and apply+cumprod() 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 rowCumprods 0.019699 0.0199165 0.0205075 0.0203345 0.0206065 0.039095
2 apply+cumprod 0.111742 0.1136960 0.1184890 0.1154635 0.1178070 0.201616
expr min lq mean median uq max
1 rowCumprods 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 apply+cumprod 5.672471 5.708634 5.777843 5.678207 5.716983 5.157079

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

Table: Benchmarking of colCumprods() and rowCumprods() 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 colCumprods 16.827 17.0745 17.74976 17.4820 17.7875 35.532
2 rowCumprods 19.699 19.9165 20.50749 20.3345 20.6065 39.095
expr min lq mean median uq max
1 colCumprods 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumprods 1.170678 1.166447 1.155367 1.163168 1.158482 1.100276

Figure: Benchmarking of colCumprods() and rowCumprods() 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 3100672 165.6    5709258 305.0  5709258 305.0
Vcells 5420527  41.4   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumprods = colCumprods(X), `apply+cumprod` = apply(X, MARGIN = 2L, 
+     FUN = cumprod), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3100666 165.6    5709258 305.0  5709258 305.0
Vcells 5425570  41.4   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumprods = rowCumprods(X), `apply+cumprod` = apply(X, MARGIN = 1L, 
+     FUN = cumprod), unit = "ms")

Table: Benchmarking of colCumprods() and apply+cumprod() 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 colCumprods 0.017995 0.0186465 0.0194841 0.0191480 0.019801 0.028707
2 apply+cumprod 0.784365 0.8574795 0.8773045 0.8729105 0.890153 1.427491
expr min lq mean median uq max
1 colCumprods 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+cumprod 43.58794 45.98608 45.02662 45.58755 44.95495 49.72623

Table: Benchmarking of rowCumprods() and apply+cumprod() 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 rowCumprods 0.017135 0.0181120 0.0190364 0.018872 0.0195365 0.029151
2 apply+cumprod 0.785872 0.8607405 0.8737364 0.873674 0.8883155 0.972038
expr min lq mean median uq max
1 rowCumprods 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+cumprod 45.86355 47.52322 45.89817 46.29472 45.46953 33.34493

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

Table: Benchmarking of colCumprods() and rowCumprods() 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 rowCumprods 17.135 18.1120 19.03641 18.872 19.5365 29.151
1 colCumprods 17.995 18.6465 19.48413 19.148 19.8010 28.707
expr min lq mean median uq max
2 rowCumprods 1.00000 1.000000 1.000000 1.000000 1.000000 1.000000
1 colCumprods 1.05019 1.029511 1.023519 1.014625 1.013539 0.984769

Figure: Benchmarking of colCumprods() and rowCumprods() 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 3100856 165.7    5709258 305.0  5709258 305.0
Vcells 5421011  41.4   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumprods = colCumprods(X), `apply+cumprod` = apply(X, MARGIN = 2L, 
+     FUN = cumprod), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3100847 165.7    5709258 305.0  5709258 305.0
Vcells 5471049  41.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumprods = rowCumprods(X), `apply+cumprod` = apply(X, MARGIN = 1L, 
+     FUN = cumprod), unit = "ms")

Table: Benchmarking of colCumprods() and apply+cumprod() 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 colCumprods 0.162444 0.1713425 0.2003627 0.194988 0.218098 0.320884
2 apply+cumprod 1.648345 1.7511105 4.6575790 1.935061 2.197555 241.029480
expr min lq mean median uq max
1 colCumprods 1.00000 1.00000 1.00000 1.000000 1.000 1.0000
2 apply+cumprod 10.14716 10.21994 23.24574 9.924003 10.076 751.1421

Table: Benchmarking of rowCumprods() and apply+cumprod() 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 rowCumprods 0.163129 0.173584 0.3100334 0.1934145 0.2083955 11.77195
2 apply+cumprod 1.628733 1.711248 2.2024568 1.9245295 2.1232570 15.87423
expr min lq mean median uq max
1 rowCumprods 1.000000 1.000000 1.000000 1.000000 1.00000 1.000000
2 apply+cumprod 9.984325 9.858328 7.103934 9.950285 10.18859 1.348479

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

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

expr min lq mean median uq max
2 rowCumprods 163.129 173.5840 310.0334 193.4145 208.3955 11771.954
1 colCumprods 162.444 171.3425 200.3627 194.9880 218.0980 320.884
expr min lq mean median uq max
2 rowCumprods 1.0000000 1.0000000 1.0000000 1.000000 1.000000 1.0000000
1 colCumprods 0.9958009 0.9870869 0.6462616 1.008135 1.046558 0.0272583

Figure: Benchmarking of colCumprods() and rowCumprods() 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 3101049 165.7    5709258 305.0  5709258 305.0
Vcells 5421573  41.4   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumprods = colCumprods(X), `apply+cumprod` = apply(X, MARGIN = 2L, 
+     FUN = cumprod), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3101043 165.7    5709258 305.0  5709258 305.0
Vcells 5471616  41.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumprods = rowCumprods(X), `apply+cumprod` = apply(X, MARGIN = 1L, 
+     FUN = cumprod), unit = "ms")

Table: Benchmarking of colCumprods() and apply+cumprod() 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 colCumprods 0.157326 0.170762 0.1872476 0.187252 0.199506 0.302430
2 apply+cumprod 0.919765 1.022550 1.2739666 1.115730 1.196760 6.949729
expr min lq mean median uq max
1 colCumprods 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
2 apply+cumprod 5.846236 5.988162 6.803648 5.958438 5.998617 22.97963

Table: Benchmarking of rowCumprods() and apply+cumprod() 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 rowCumprods 0.170043 0.1795145 0.2612241 0.2088915 0.2209475 5.549376
2 apply+cumprod 0.963364 1.0610100 1.2855723 1.1820010 1.2416525 6.517151
expr min lq mean median uq max
1 rowCumprods 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 apply+cumprod 5.665414 5.910442 4.921338 5.658445 5.619672 1.174394

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

Table: Benchmarking of colCumprods() and rowCumprods() 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 colCumprods 157.326 170.7620 187.2476 187.2520 199.5060 302.430
2 rowCumprods 170.043 179.5145 261.2241 208.8915 220.9475 5549.376
expr min lq mean median uq max
1 colCumprods 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
2 rowCumprods 1.080832 1.051255 1.395074 1.115563 1.107473 18.34929

Figure: Benchmarking of colCumprods() and rowCumprods() 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, range = c(-1, 1))

Results

10x10 double matrix

> X <- data[["10x10"]]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3101257 165.7    5709258 305.0  5709258 305.0
Vcells 5537961  42.3   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumprods = colCumprods(X), `apply+cumprod` = apply(X, MARGIN = 2L, 
+     FUN = cumprod), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3101242 165.7    5709258 305.0  5709258 305.0
Vcells 5538089  42.3   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumprods = rowCumprods(X), `apply+cumprod` = apply(X, MARGIN = 1L, 
+     FUN = cumprod), unit = "ms")

Table: Benchmarking of colCumprods() and apply+cumprod() 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 colCumprods 0.000957 0.0012555 0.0016875 0.001573 0.001911 0.010514
2 apply+cumprod 0.025373 0.0259485 0.0274649 0.026166 0.026514 0.130695
expr min lq mean median uq max
1 colCumprods 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+cumprod 26.51306 20.66786 16.27551 16.63446 13.87441 12.43057

Table: Benchmarking of rowCumprods() and apply+cumprod() 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 rowCumprods 0.000964 0.0014235 0.0018137 0.0017945 0.0019705 0.010656
2 apply+cumprod 0.024430 0.0254435 0.0265325 0.0257410 0.0260540 0.094668
expr min lq mean median uq max
1 rowCumprods 1.00000 1.0000 1.00000 1.00000 1.00000 1.000000
2 apply+cumprod 25.34232 17.8739 14.62863 14.34439 13.22202 8.884009

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

Table: Benchmarking of colCumprods() and rowCumprods() 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 colCumprods 957 1255.5 1687.50 1573.0 1911.0 10514
2 rowCumprods 964 1423.5 1813.74 1794.5 1970.5 10656
expr min lq mean median uq max
1 colCumprods 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumprods 1.007314 1.133811 1.074809 1.140814 1.031135 1.013506

Figure: Benchmarking of colCumprods() and rowCumprods() 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 3101435 165.7    5709258 305.0  5709258 305.0
Vcells 5538071  42.3   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumprods = colCumprods(X), `apply+cumprod` = apply(X, MARGIN = 2L, 
+     FUN = cumprod), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3101429 165.7    5709258 305.0  5709258 305.0
Vcells 5548114  42.4   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumprods = rowCumprods(X), `apply+cumprod` = apply(X, MARGIN = 1L, 
+     FUN = cumprod), unit = "ms")

Table: Benchmarking of colCumprods() and apply+cumprod() 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 colCumprods 0.010369 0.0109535 0.0119505 0.0113065 0.0120065 0.049808
2 apply+cumprod 0.205167 0.2096305 0.2170450 0.2110580 0.2175210 0.361471
expr min lq mean median uq max
1 colCumprods 1.00000 1.00000 1.00000 1.00000 1.00000 1.000000
2 apply+cumprod 19.78658 19.13822 18.16204 18.66696 18.11694 7.257288

Table: Benchmarking of rowCumprods() and apply+cumprod() 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 rowCumprods 0.008117 0.0087290 0.0095054 0.0092025 0.0097095 0.020993
2 apply+cumprod 0.166112 0.1690535 0.1754378 0.1699895 0.1719100 0.349950
expr min lq mean median uq max
1 rowCumprods 1.0000 1.00000 1.00000 1.0000 1.00000 1.00000
2 apply+cumprod 20.4647 19.36688 18.45655 18.4721 17.70534 16.66984

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

Table: Benchmarking of colCumprods() and rowCumprods() 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 rowCumprods 8.117 8.7290 9.50545 9.2025 9.7095 20.993
1 colCumprods 10.369 10.9535 11.95048 11.3065 12.0065 49.808
expr min lq mean median uq max
2 rowCumprods 1.000000 1.00000 1.000000 1.000000 1.000000 1.0000
1 colCumprods 1.277442 1.25484 1.257224 1.228633 1.236572 2.3726

Figure: Benchmarking of colCumprods() and rowCumprods() 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 3101625 165.7    5709258 305.0  5709258 305.0
Vcells 5538955  42.3   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumprods = colCumprods(X), `apply+cumprod` = apply(X, MARGIN = 2L, 
+     FUN = cumprod), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3101619 165.7    5709258 305.0  5709258 305.0
Vcells 5548998  42.4   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumprods = rowCumprods(X), `apply+cumprod` = apply(X, MARGIN = 1L, 
+     FUN = cumprod), unit = "ms")

Table: Benchmarking of colCumprods() and apply+cumprod() 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 colCumprods 0.024543 0.0249125 0.0256396 0.0252260 0.0256205 0.046757
2 apply+cumprod 0.413699 0.4159710 0.4210708 0.4190815 0.4219310 0.497122
expr min lq mean median uq max
1 colCumprods 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+cumprod 16.85609 16.69728 16.42265 16.61308 16.46849 10.63203

Table: Benchmarking of rowCumprods() and apply+cumprod() 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 rowCumprods 0.023255 0.025001 0.0298212 0.0259615 0.026972 0.099084
2 apply+cumprod 0.366003 0.369050 0.3836890 0.3778690 0.381283 0.595822
expr min lq mean median uq max
1 rowCumprods 1.00000 1.00000 1.0000 1.00000 1.00000 1.000000
2 apply+cumprod 15.73868 14.76141 12.8663 14.55498 14.13625 6.013302

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

Table: Benchmarking of colCumprods() and rowCumprods() 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 colCumprods 24.543 24.9125 25.63963 25.2260 25.6205 46.757
2 rowCumprods 23.255 25.0010 29.82124 25.9615 26.9720 99.084
expr min lq mean median uq max
1 colCumprods 1.0000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumprods 0.9475207 1.003552 1.163092 1.029156 1.052751 2.119127

Figure: Benchmarking of colCumprods() and rowCumprods() 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 3101814 165.7    5709258 305.0  5709258 305.0
Vcells 5539997  42.3   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumprods = colCumprods(X), `apply+cumprod` = apply(X, MARGIN = 2L, 
+     FUN = cumprod), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3101808 165.7    5709258 305.0  5709258 305.0
Vcells 5550040  42.4   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumprods = rowCumprods(X), `apply+cumprod` = apply(X, MARGIN = 1L, 
+     FUN = cumprod), unit = "ms")

Table: Benchmarking of colCumprods() and apply+cumprod() 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 colCumprods 0.010095 0.0113285 0.0120755 0.0117065 0.0125125 0.022029
2 apply+cumprod 0.740065 0.8032355 0.8206785 0.8191090 0.8358040 0.888269
expr min lq mean median uq max
1 colCumprods 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+cumprod 73.31005 70.90396 67.96251 69.97044 66.79752 40.32271

Table: Benchmarking of rowCumprods() and apply+cumprod() 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 rowCumprods 0.009671 0.0109705 0.0119001 0.0115055 0.0121585 0.021250
2 apply+cumprod 0.744983 0.8057400 0.8225679 0.8211795 0.8416245 0.895346
expr min lq mean median uq max
1 rowCumprods 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+cumprod 77.03267 73.44606 69.12283 71.37278 69.22108 42.13393

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

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

expr min lq mean median uq max
2 rowCumprods 9.671 10.9705 11.90009 11.5055 12.1585 21.250
1 colCumprods 10.095 11.3285 12.07546 11.7065 12.5125 22.029
expr min lq mean median uq max
2 rowCumprods 1.000000 1.000000 1.000000 1.00000 1.000000 1.000000
1 colCumprods 1.043842 1.032633 1.014737 1.01747 1.029115 1.036659

Figure: Benchmarking of colCumprods() and rowCumprods() 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 3101998 165.7    5709258 305.0  5709258 305.0
Vcells 5540120  42.3   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumprods = colCumprods(X), `apply+cumprod` = apply(X, MARGIN = 2L, 
+     FUN = cumprod), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3101989 165.7    5709258 305.0  5709258 305.0
Vcells 5640158  43.1   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumprods = rowCumprods(X), `apply+cumprod` = apply(X, MARGIN = 1L, 
+     FUN = cumprod), unit = "ms")

Table: Benchmarking of colCumprods() and apply+cumprod() 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 colCumprods 0.092531 0.1023675 0.112034 0.1085595 0.1218925 0.162247
2 apply+cumprod 1.882893 1.9782800 2.460674 2.1001155 2.3842770 12.407964
expr min lq mean median uq max
1 colCumprods 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+cumprod 20.34878 19.32527 21.96363 19.34529 19.56049 76.47577

Table: Benchmarking of rowCumprods() and apply+cumprod() 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 rowCumprods 0.069477 0.0782755 0.2282816 0.086561 0.0963115 13.99169
2 apply+cumprod 1.513860 1.6559535 2.1092773 1.872459 2.0174680 12.80392
expr min lq mean median uq max
1 rowCumprods 1.00000 1.00000 1.000000 1.00000 1.00000 1.0000000
2 apply+cumprod 21.78937 21.15545 9.239803 21.63166 20.94732 0.9151094

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

Table: Benchmarking of colCumprods() and rowCumprods() 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
2 rowCumprods 69.477 78.2755 228.2816 86.5610 96.3115 13991.686
1 colCumprods 92.531 102.3675 112.0340 108.5595 121.8925 162.247
expr min lq mean median uq max
2 rowCumprods 1.000000 1.000000 1.0000000 1.000000 1.000000 1.000000
1 colCumprods 1.331822 1.307785 0.4907711 1.254139 1.265607 0.011596

Figure: Benchmarking of colCumprods() and rowCumprods() 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 3102194 165.7    5709258 305.0  5709258 305.0
Vcells 5541346  42.3   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumprods = colCumprods(X), `apply+cumprod` = apply(X, MARGIN = 2L, 
+     FUN = cumprod), unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3102185 165.7    5709258 305.0  5709258 305.0
Vcells 5641384  43.1   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumprods = rowCumprods(X), `apply+cumprod` = apply(X, MARGIN = 1L, 
+     FUN = cumprod), unit = "ms")

Table: Benchmarking of colCumprods() and apply+cumprod() 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 colCumprods 0.238808 0.240286 0.2469832 0.2428435 0.2465275 0.294250
2 apply+cumprod 3.475465 3.491878 3.7121315 3.4980985 3.5098470 9.665839
expr min lq mean median uq max
1 colCumprods 1.00000 1.00000 1.0000 1.00000 1.00000 1.00000
2 apply+cumprod 14.55339 14.53217 15.0299 14.40474 14.23714 32.84907

Table: Benchmarking of rowCumprods() and apply+cumprod() 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 rowCumprods 0.210230 0.213321 0.2222368 0.216858 0.2238835 0.271953
2 apply+cumprod 3.509805 3.525008 3.7583221 3.534352 3.6329115 8.797999
expr min lq mean median uq max
1 rowCumprods 1.00000 1.00000 1.00000 1.000 1.00000 1.00000
2 apply+cumprod 16.69507 16.52443 16.91134 16.298 16.22679 32.35117

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

Table: Benchmarking of colCumprods() and rowCumprods() 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
2 rowCumprods 210.230 213.321 222.2368 216.8580 223.8835 271.953
1 colCumprods 238.808 240.286 246.9832 242.8435 246.5275 294.250
expr min lq mean median uq max
2 rowCumprods 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
1 colCumprods 1.135937 1.126406 1.111351 1.119827 1.101142 1.081988

Figure: Benchmarking of colCumprods() and rowCumprods() 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.8 secs.

Reproducibility

To reproduce this report, do:

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

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