colRowCumsums - HenrikBengtsson/matrixStats GitHub Wiki

matrixStats: Benchmark report


colCumsums() and rowCumsums() benchmarks

This report benchmark the performance of colCumsums() and rowCumsums() against alternative methods.

Alternative methods

  • apply() + cumsum()

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 3110114 166.1    5709258 305.0  5709258 305.0
Vcells 5857289  44.7   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums = colCumsums(X), `apply+cumsum` = apply(X, MARGIN = 2L, FUN = cumsum), 
+     unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3108840 166.1    5709258 305.0  5709258 305.0
Vcells 5853677  44.7   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums = rowCumsums(X), `apply+cumsum` = apply(X, MARGIN = 1L, FUN = cumsum), 
+     unit = "ms")

Table: Benchmarking of colCumsums() and apply+cumsum() 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 colCumsums 0.001095 0.001293 0.0016890 0.00155 0.001870 0.009225
2 apply+cumsum 0.024941 0.025709 0.0269915 0.02597 0.026415 0.100546
expr min lq mean median uq max
1 colCumsums 1.00000 1.00000 1.00000 1.00000 1.00000 1.0000
2 apply+cumsum 22.77717 19.88322 15.98087 16.75484 14.12567 10.8993

Table: Benchmarking of rowCumsums() and apply+cumsum() 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 rowCumsums 0.001051 0.001536 0.0018836 0.0018205 0.0019985 0.011396
2 apply+cumsum 0.024872 0.025617 0.0274043 0.0260060 0.0265870 0.129755
expr min lq mean median uq max
1 rowCumsums 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+cumsum 23.66508 16.67773 14.54928 14.28509 13.30348 11.38601

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

Table: Benchmarking of colCumsums() and rowCumsums() 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 colCumsums 1.095 1.293 1.68899 1.5500 1.8700 9.225
2 rowCumsums 1.051 1.536 1.88355 1.8205 1.9985 11.396
expr min lq mean median uq max
1 colCumsums 1.0000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumsums 0.9598174 1.187935 1.115193 1.174516 1.068717 1.235339

Figure: Benchmarking of colCumsums() and rowCumsums() 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 3107395 166.0    5709258 305.0  5709258 305.0
Vcells 5470168  41.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums = colCumsums(X), `apply+cumsum` = apply(X, MARGIN = 2L, FUN = cumsum), 
+     unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3107389 166.0    5709258 305.0  5709258 305.0
Vcells 5475211  41.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums = rowCumsums(X), `apply+cumsum` = apply(X, MARGIN = 1L, FUN = cumsum), 
+     unit = "ms")

Table: Benchmarking of colCumsums() and apply+cumsum() 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 colCumsums 0.017256 0.0176950 0.0185754 0.0179605 0.018402 0.048429
2 apply+cumsum 0.171849 0.1742205 0.1802480 0.1754160 0.178504 0.320220
expr min lq mean median uq max
1 colCumsums 1.000000 1.000000 1.000000 1.000000 1.00000 1.000000
2 apply+cumsum 9.958797 9.845747 9.703563 9.766766 9.70025 6.612154

Table: Benchmarking of rowCumsums() and apply+cumsum() 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 rowCumsums 0.018053 0.0184745 0.0195422 0.018860 0.0192855 0.043532
2 apply+cumsum 0.172852 0.1743155 0.1798394 0.175312 0.1766195 0.349658
expr min lq mean median uq max
1 rowCumsums 1.000000 1.000000 1.000000 1.00000 1.00000 1.000000
2 apply+cumsum 9.574697 9.435465 9.202626 9.29544 9.15815 8.032206

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

Table: Benchmarking of colCumsums() and rowCumsums() 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 colCumsums 17.256 17.6950 18.57544 17.9605 18.4020 48.429
2 rowCumsums 18.053 18.4745 19.54218 18.8600 19.2855 43.532
expr min lq mean median uq max
1 colCumsums 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowCumsums 1.046187 1.044052 1.052044 1.050082 1.048011 0.8988829

Figure: Benchmarking of colCumsums() and rowCumsums() 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 3108128 166.0    5709258 305.0  5709258 305.0
Vcells 5473681  41.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums = colCumsums(X), `apply+cumsum` = apply(X, MARGIN = 2L, FUN = cumsum), 
+     unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3108119 166.0    5709258 305.0  5709258 305.0
Vcells 5478719  41.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums = rowCumsums(X), `apply+cumsum` = apply(X, MARGIN = 1L, FUN = cumsum), 
+     unit = "ms")

Table: Benchmarking of colCumsums() and apply+cumsum() 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 colCumsums 0.016687 0.017090 0.0179091 0.0174425 0.0177965 0.048515
2 apply+cumsum 0.106618 0.111433 0.1137818 0.1125610 0.1145365 0.199408
expr min lq mean median uq max
1 colCumsums 1.000000 1.000000 1.000000 1.000000 1.0000 1.000000
2 apply+cumsum 6.389285 6.520363 6.353298 6.453261 6.4359 4.110234

Table: Benchmarking of rowCumsums() and apply+cumsum() 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 rowCumsums 0.019551 0.0200910 0.0243383 0.0204990 0.0209795 0.296231
2 apply+cumsum 0.102220 0.1078475 0.1167199 0.1107865 0.1116970 0.717267
expr min lq mean median uq max
1 rowCumsums 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
2 apply+cumsum 5.228377 5.367951 4.795729 5.404483 5.324102 2.42131

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

Table: Benchmarking of colCumsums() and rowCumsums() 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 colCumsums 16.687 17.090 17.9091 17.4425 17.7965 48.515
2 rowCumsums 19.551 20.091 24.3383 20.4990 20.9795 296.231
expr min lq mean median uq max
1 colCumsums 1.000000 1.0000 1.000000 1.000000 1.000000 1.000000
2 rowCumsums 1.171631 1.1756 1.358991 1.175233 1.178855 6.105967

Figure: Benchmarking of colCumsums() and rowCumsums() 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 3108314 166.1    5709258 305.0  5709258 305.0
Vcells 5474366  41.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums = colCumsums(X), `apply+cumsum` = apply(X, MARGIN = 2L, FUN = cumsum), 
+     unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3108308 166.1    5709258 305.0  5709258 305.0
Vcells 5479409  41.9   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums = rowCumsums(X), `apply+cumsum` = apply(X, MARGIN = 1L, FUN = cumsum), 
+     unit = "ms")

Table: Benchmarking of colCumsums() and apply+cumsum() 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 colCumsums 0.017864 0.0184425 0.0192490 0.0190685 0.0195705 0.032377
2 apply+cumsum 0.752238 0.7930680 0.8180328 0.8109245 0.8310740 1.072476
expr min lq mean median uq max
1 colCumsums 1.00000 1.0000 1.00000 1.00000 1.00000 1.00000
2 apply+cumsum 42.10916 43.0022 42.49742 42.52692 42.46565 33.12463

Table: Benchmarking of rowCumsums() and apply+cumsum() 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 rowCumsums 0.017210 0.0177510 0.0195783 0.0183045 0.0188795 0.046978
2 apply+cumsum 0.753124 0.7921245 0.8118253 0.7999565 0.8167745 1.306501
expr min lq mean median uq max
1 rowCumsums 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+cumsum 43.76084 44.62422 41.46561 43.70272 43.26251 27.81091

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

Table: Benchmarking of colCumsums() and rowCumsums() 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 rowCumsums 17.210 17.7510 19.57828 18.3045 18.8795 46.978
1 colCumsums 17.864 18.4425 19.24900 19.0685 19.5705 32.377
expr min lq mean median uq max
2 rowCumsums 1.000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
1 colCumsums 1.038001 1.038956 0.9831814 1.041738 1.036601 0.6891949

Figure: Benchmarking of colCumsums() and rowCumsums() 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 3108498 166.1    5709258 305.0  5709258 305.0
Vcells 5474848  41.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums = colCumsums(X), `apply+cumsum` = apply(X, MARGIN = 2L, FUN = cumsum), 
+     unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3108489 166.1    5709258 305.0  5709258 305.0
Vcells 5524886  42.2   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums = rowCumsums(X), `apply+cumsum` = apply(X, MARGIN = 1L, FUN = cumsum), 
+     unit = "ms")

Table: Benchmarking of colCumsums() and apply+cumsum() 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 colCumsums 0.162260 0.164089 0.1729198 0.1711255 0.178054 0.217846
2 apply+cumsum 1.507841 1.556263 1.8620912 1.5888660 1.645371 13.510441
expr min lq mean median uq max
1 colCumsums 1.000000 1.000000 1.00000 1.0000 1.000000 1.00000
2 apply+cumsum 9.292746 9.484258 10.76853 9.2848 9.240857 62.01831

Table: Benchmarking of rowCumsums() and apply+cumsum() 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 rowCumsums 0.163137 0.1675025 0.181545 0.1722575 0.177399 0.84700
2 apply+cumsum 1.528956 1.5720130 1.869777 1.5992720 1.637102 13.08279
expr min lq mean median uq max
1 rowCumsums 1.000000 1.000000 1.00000 1.000000 1.000000 1.00000
2 apply+cumsum 9.372221 9.385012 10.29925 9.284194 9.228361 15.44604

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

Table: Benchmarking of colCumsums() and rowCumsums() 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 colCumsums 162.260 164.0890 172.9198 171.1255 178.054 217.846
2 rowCumsums 163.137 167.5025 181.5450 172.2575 177.399 847.000
expr min lq mean median uq max
1 colCumsums 1.000000 1.000000 1.00000 1.000000 1.0000000 1.000000
2 rowCumsums 1.005405 1.020803 1.04988 1.006615 0.9963213 3.888068

Figure: Benchmarking of colCumsums() and rowCumsums() 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 3108691 166.1    5709258 305.0  5709258 305.0
Vcells 5475407  41.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums = colCumsums(X), `apply+cumsum` = apply(X, MARGIN = 2L, FUN = cumsum), 
+     unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3108685 166.1    5709258 305.0  5709258 305.0
Vcells 5525450  42.2   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums = rowCumsums(X), `apply+cumsum` = apply(X, MARGIN = 1L, FUN = cumsum), 
+     unit = "ms")

Table: Benchmarking of colCumsums() and apply+cumsum() 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 colCumsums 0.157001 0.1590005 0.1677189 0.164210 0.1724045 0.201525
2 apply+cumsum 0.850301 0.8738420 1.0361679 0.896856 0.9465080 6.867605
expr min lq mean median uq max
1 colCumsums 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
2 apply+cumsum 5.415895 5.495844 6.178002 5.461641 5.490042 34.07818

Table: Benchmarking of rowCumsums() and apply+cumsum() 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 rowCumsums 0.170063 0.1724545 0.1847704 0.1794145 0.1843415 0.313704
2 apply+cumsum 0.884892 0.9106820 1.1361354 0.9311325 0.9840030 11.234460
expr min lq mean median uq max
1 rowCumsums 1.000000 1.000000 1.000000 1.00000 1.000000 1.00000
2 apply+cumsum 5.203319 5.280709 6.148905 5.18984 5.337935 35.81229

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

Table: Benchmarking of colCumsums() and rowCumsums() 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 colCumsums 157.001 159.0005 167.7189 164.2100 172.4045 201.525
2 rowCumsums 170.063 172.4545 184.7704 179.4145 184.3415 313.704
expr min lq mean median uq max
1 colCumsums 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
2 rowCumsums 1.083197 1.084616 1.101667 1.092592 1.069238 1.55665

Figure: Benchmarking of colCumsums() and rowCumsums() 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 3108899 166.1    5709258 305.0  5709258 305.0
Vcells 5591749  42.7   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums = colCumsums(X), `apply+cumsum` = apply(X, MARGIN = 2L, FUN = cumsum), 
+     unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3108884 166.1    5709258 305.0  5709258 305.0
Vcells 5591877  42.7   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums = rowCumsums(X), `apply+cumsum` = apply(X, MARGIN = 1L, FUN = cumsum), 
+     unit = "ms")

Table: Benchmarking of colCumsums() and apply+cumsum() 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 colCumsums 0.000951 0.0013245 0.0016868 0.001563 0.0018685 0.009846
2 apply+cumsum 0.025061 0.0258960 0.0273502 0.026181 0.0264655 0.129141
expr min lq mean median uq max
1 colCumsums 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+cumsum 26.35226 19.55153 16.21408 16.75048 14.16404 13.11609

Table: Benchmarking of rowCumsums() and apply+cumsum() 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 rowCumsums 0.001033 0.0014590 0.0018279 0.001752 0.0019580 0.012744
2 apply+cumsum 0.024794 0.0256725 0.0270697 0.025953 0.0263155 0.120387
expr min lq mean median uq max
1 rowCumsums 1.00000 1.00000 1.00000 1.00000 1.00000 1.000000
2 apply+cumsum 24.00194 17.59596 14.80912 14.81336 13.43999 9.446563

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

Table: Benchmarking of colCumsums() and rowCumsums() 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 colCumsums 951 1324.5 1686.82 1563 1868.5 9846
2 rowCumsums 1033 1459.0 1827.91 1752 1958.0 12744
expr min lq mean median uq max
1 colCumsums 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumsums 1.086225 1.101548 1.083643 1.120921 1.047899 1.294333

Figure: Benchmarking of colCumsums() and rowCumsums() 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 3109077 166.1    5709258 305.0  5709258 305.0
Vcells 5591859  42.7   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums = colCumsums(X), `apply+cumsum` = apply(X, MARGIN = 2L, FUN = cumsum), 
+     unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3109071 166.1    5709258 305.0  5709258 305.0
Vcells 5601902  42.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums = rowCumsums(X), `apply+cumsum` = apply(X, MARGIN = 1L, FUN = cumsum), 
+     unit = "ms")

Table: Benchmarking of colCumsums() and apply+cumsum() 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 colCumsums 0.010349 0.0109360 0.0119258 0.0112805 0.0117620 0.053442
2 apply+cumsum 0.202861 0.2056205 0.2133436 0.2073775 0.2139005 0.353507
expr min lq mean median uq max
1 colCumsums 1.00000 1.00000 1.00000 1.00000 1.00000 1.000000
2 apply+cumsum 19.60199 18.80217 17.88926 18.38372 18.18573 6.614779

Table: Benchmarking of rowCumsums() and apply+cumsum() 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 rowCumsums 0.008235 0.0088715 0.0095574 0.0093015 0.0098925 0.016764
2 apply+cumsum 0.160743 0.1649900 0.1706646 0.1662630 0.1678295 0.302181
expr min lq mean median uq max
1 rowCumsums 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+cumsum 19.51949 18.59776 17.85673 17.87486 16.96533 18.02559

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

Table: Benchmarking of colCumsums() and rowCumsums() 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 rowCumsums 8.235 8.8715 9.55744 9.3015 9.8925 16.764
1 colCumsums 10.349 10.9360 11.92579 11.2805 11.7620 53.442
expr min lq mean median uq max
2 rowCumsums 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
1 colCumsums 1.256709 1.232711 1.247802 1.212761 1.188982 3.187903

Figure: Benchmarking of colCumsums() and rowCumsums() 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 3109267 166.1    5709258 305.0  5709258 305.0
Vcells 5592736  42.7   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums = colCumsums(X), `apply+cumsum` = apply(X, MARGIN = 2L, FUN = cumsum), 
+     unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3109261 166.1    5709258 305.0  5709258 305.0
Vcells 5602779  42.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums = rowCumsums(X), `apply+cumsum` = apply(X, MARGIN = 1L, FUN = cumsum), 
+     unit = "ms")

Table: Benchmarking of colCumsums() and apply+cumsum() 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 colCumsums 0.011687 0.0121495 0.0129607 0.0125775 0.0128600 0.045127
2 apply+cumsum 0.140885 0.1427040 0.1471542 0.1444200 0.1472245 0.239505
expr min lq mean median uq max
1 colCumsums 1.00000 1.00000 1.00000 1.00000 1.00000 1.000000
2 apply+cumsum 12.05485 11.74567 11.35386 11.48241 11.44825 5.307355

Table: Benchmarking of rowCumsums() and apply+cumsum() 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 rowCumsums 0.010043 0.011007 0.0120208 0.011606 0.0124735 0.030249
2 apply+cumsum 0.099419 0.101546 0.1067722 0.103022 0.1076780 0.180666
expr min lq mean median uq max
1 rowCumsums 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 apply+cumsum 9.899333 9.225584 8.882294 8.876615 8.632541 5.972627

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

Table: Benchmarking of colCumsums() and rowCumsums() 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
2 rowCumsums 10.043 11.0070 12.02079 11.6060 12.4735 30.249
1 colCumsums 11.687 12.1495 12.96071 12.5775 12.8600 45.127
expr min lq mean median uq max
2 rowCumsums 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
1 colCumsums 1.163696 1.103798 1.078191 1.083707 1.030986 1.491851

Figure: Benchmarking of colCumsums() and rowCumsums() 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 3109456 166.1    5709258 305.0  5709258 305.0
Vcells 5593759  42.7   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums = colCumsums(X), `apply+cumsum` = apply(X, MARGIN = 2L, FUN = cumsum), 
+     unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3109450 166.1    5709258 305.0  5709258 305.0
Vcells 5603802  42.8   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums = rowCumsums(X), `apply+cumsum` = apply(X, MARGIN = 1L, FUN = cumsum), 
+     unit = "ms")

Table: Benchmarking of colCumsums() and apply+cumsum() 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 colCumsums 0.010178 0.011411 0.0123421 0.0118735 0.0123915 0.023636
2 apply+cumsum 0.746431 0.789557 0.8030532 0.7986635 0.8121960 0.877837
expr min lq mean median uq max
1 colCumsums 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
2 apply+cumsum 73.33769 69.19262 65.06638 67.26437 65.54461 37.13983

Table: Benchmarking of rowCumsums() and apply+cumsum() 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 rowCumsums 0.009703 0.0110745 0.0118773 0.0114655 0.0121805 0.019422
2 apply+cumsum 0.736904 0.7909285 0.8010720 0.7968600 0.8128895 0.879196
expr min lq mean median uq max
1 rowCumsums 1.000 1.00000 1.0000 1.00000 1.00000 1.00000
2 apply+cumsum 75.946 71.41889 67.4458 69.50068 66.73696 45.26805

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

Table: Benchmarking of colCumsums() and rowCumsums() 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 rowCumsums 9.703 11.0745 11.87727 11.4655 12.1805 19.422
1 colCumsums 10.178 11.4110 12.34206 11.8735 12.3915 23.636
expr min lq mean median uq max
2 rowCumsums 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
1 colCumsums 1.048954 1.030385 1.039133 1.035585 1.017323 1.21697

Figure: Benchmarking of colCumsums() and rowCumsums() 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 3109640 166.1    5709258 305.0  5709258 305.0
Vcells 5593882  42.7   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums = colCumsums(X), `apply+cumsum` = apply(X, MARGIN = 2L, FUN = cumsum), 
+     unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3109631 166.1    5709258 305.0  5709258 305.0
Vcells 5693920  43.5   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums = rowCumsums(X), `apply+cumsum` = apply(X, MARGIN = 1L, FUN = cumsum), 
+     unit = "ms")

Table: Benchmarking of colCumsums() and apply+cumsum() 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 colCumsums 0.092020 0.099466 0.108740 0.1061305 0.1159415 0.170128
2 apply+cumsum 1.846279 1.888750 2.369293 1.9863660 2.2874110 12.396982
expr min lq mean median uq max
1 colCumsums 1.00000 1.0000 1.00000 1.00000 1.00000 1.00000
2 apply+cumsum 20.06389 18.9889 21.78861 18.71626 19.72901 72.86856

Table: Benchmarking of rowCumsums() and apply+cumsum() 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 rowCumsums 0.069659 0.076171 0.1811151 0.086158 0.0939665 9.429972
2 apply+cumsum 1.440417 1.574412 1.9984813 1.764504 1.9370215 12.568730
expr min lq mean median uq max
1 rowCumsums 1.00000 1.00000 1.00000 1.00000 1.00000 1.000000
2 apply+cumsum 20.67812 20.66944 11.03432 20.47987 20.61396 1.332849

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

Table: Benchmarking of colCumsums() and rowCumsums() 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 rowCumsums 69.659 76.171 181.1151 86.1580 93.9665 9429.972
1 colCumsums 92.020 99.466 108.7400 106.1305 115.9415 170.128
expr min lq mean median uq max
2 rowCumsums 1.000000 1.000000 1.0000000 1.000000 1.00000 1.0000000
1 colCumsums 1.321007 1.305825 0.6003916 1.231812 1.23386 0.0180412

Figure: Benchmarking of colCumsums() and rowCumsums() 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 3109839 166.1    5709258 305.0  5709258 305.0
Vcells 5595102  42.7   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums = colCumsums(X), `apply+cumsum` = apply(X, MARGIN = 2L, FUN = cumsum), 
+     unit = "ms")
> X <- t(X)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3109827 166.1    5709258 305.0  5709258 305.0
Vcells 5695135  43.5   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums = rowCumsums(X), `apply+cumsum` = apply(X, MARGIN = 1L, FUN = cumsum), 
+     unit = "ms")

Table: Benchmarking of colCumsums() and apply+cumsum() 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 colCumsums 0.105626 0.115681 0.1736255 0.1246615 0.131595 5.044977
2 apply+cumsum 0.821538 0.855851 1.0302632 0.9243780 0.997576 6.030735
expr min lq mean median uq max
1 colCumsums 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 apply+cumsum 7.777801 7.398371 5.933823 7.415104 7.580653 1.195394

Table: Benchmarking of rowCumsums() and apply+cumsum() 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 rowCumsums 0.074125 0.078856 0.0868615 0.085673 0.091320 0.129372
2 apply+cumsum 0.846315 0.916516 1.1850474 1.002492 1.060085 6.211344
expr min lq mean median uq max
1 rowCumsums 1.0000 1.00000 1.00000 1.00000 1.00000 1.0000
2 apply+cumsum 11.4174 11.62265 13.64296 11.70137 11.60846 48.0115

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

Table: Benchmarking of colCumsums() and rowCumsums() 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 rowCumsums 74.125 78.856 86.86148 85.6730 91.320 129.372
1 colCumsums 105.626 115.681 173.62553 124.6615 131.595 5044.977
expr min lq mean median uq max
2 rowCumsums 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000
1 colCumsums 1.424971 1.466991 1.998878 1.455085 1.441032 38.9959

Figure: Benchmarking of colCumsums() and rowCumsums() 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 23.53 secs.

Reproducibility

To reproduce this report, do:

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

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