colRowCumsums_subset - HenrikBengtsson/matrixStats GitHub Wiki

matrixStats: Benchmark report


colCumsums() and rowCumsums() benchmarks on subsetted computation

This report benchmark the performance of colCumsums() and rowCumsums() on subsetted computation.

Data type "integer"

Data

> rmatrix <- function(nrow, ncol, mode = c("logical", "double", "integer", "index"), range = c(-100, 
+     +100), na_prob = 0) {
+     mode <- match.arg(mode)
+     n <- nrow * ncol
+     if (mode == "logical") {
+         x <- sample(c(FALSE, TRUE), size = n, replace = TRUE)
+     }     else if (mode == "index") {
+         x <- seq_len(n)
+         mode <- "integer"
+     }     else {
+         x <- runif(n, min = range[1], max = range[2])
+     }
+     storage.mode(x) <- mode
+     if (na_prob > 0) 
+         x[sample(n, size = na_prob * n)] <- NA
+     dim(x) <- c(nrow, ncol)
+     x
+ }
> rmatrices <- function(scale = 10, seed = 1, ...) {
+     set.seed(seed)
+     data <- list()
+     data[[1]] <- rmatrix(nrow = scale * 1, ncol = scale * 1, ...)
+     data[[2]] <- rmatrix(nrow = scale * 10, ncol = scale * 10, ...)
+     data[[3]] <- rmatrix(nrow = scale * 100, ncol = scale * 1, ...)
+     data[[4]] <- t(data[[3]])
+     data[[5]] <- rmatrix(nrow = scale * 10, ncol = scale * 100, ...)
+     data[[6]] <- t(data[[5]])
+     names(data) <- sapply(data, FUN = function(x) paste(dim(x), collapse = "x"))
+     data
+ }
> data <- rmatrices(mode = mode)

Results

10x10 integer matrix

> X <- data[["10x10"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3105970 165.9    5709258 305.0  5709258 305.0
Vcells 5780705  44.2   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums_X_S = colCumsums(X_S), `colCumsums(X, rows, cols)` = colCumsums(X, 
+     rows = rows, cols = cols), `colCummins(X[rows, cols])` = colCumsums(X[rows, cols]), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3105133 165.9    5709258 305.0  5709258 305.0
Vcells 5778646  44.1   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums_X_S = rowCumsums(X_S), `rowCumsums(X, cols, rows)` = rowCumsums(X, 
+     rows = cols, cols = rows), `rowCumsums(X[cols, rows])` = rowCumsums(X[cols, rows]), unit = "ms")

Table: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on integer+10x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 0.000939 0.0011200 0.0020650 0.0011555 0.0012275 0.087492
2 colCumsums(X, rows, cols) 0.001041 0.0012850 0.0013946 0.0013405 0.0014460 0.003240
3 colCummins(X[rows, cols]) 0.001346 0.0017835 0.0019462 0.0018520 0.0019780 0.007500
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
2 colCumsums(X, rows, cols) 1.108626 1.147321 0.6753186 1.160104 1.178004 0.0370320
3 colCummins(X[rows, cols]) 1.433440 1.592411 0.9424563 1.602769 1.611405 0.0857221

Table: Benchmarking of rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on integer+10x10 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCumsums_X_S 0.000931 0.0011165 0.0012284 0.0011745 0.0012685 0.003049
2 rowCumsums(X, cols, rows) 0.001089 0.0013250 0.0020978 0.0013640 0.0014765 0.070384
3 rowCumsums(X[cols, rows]) 0.001458 0.0018305 0.0019678 0.0019260 0.0020250 0.003299
expr min lq mean median uq max
1 rowCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumsums(X, cols, rows) 1.169710 1.186744 1.707766 1.161345 1.163973 23.084290
3 rowCumsums(X[cols, rows]) 1.566058 1.639498 1.601913 1.639847 1.596374 1.081994

Figure: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on integer+10x10 data as well as rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCumsums_X_S() and rowCumsums_X_S() on integer+10x10 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 939 1120.0 2065.04 1155.5 1227.5 87492
2 rowCumsums_X_S 931 1116.5 1228.40 1174.5 1268.5 3049
expr min lq mean median uq max
1 colCumsums_X_S 1.0000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
2 rowCumsums_X_S 0.9914803 0.996875 0.5948553 1.016443 1.033401 0.0348489

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

100x100 integer matrix

> X <- data[["100x100"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3103717 165.8    5709258 305.0  5709258 305.0
Vcells 5447397  41.6   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums_X_S = colCumsums(X_S), `colCumsums(X, rows, cols)` = colCumsums(X, 
+     rows = rows, cols = cols), `colCummins(X[rows, cols])` = colCumsums(X[rows, cols]), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3103711 165.8    5709258 305.0  5709258 305.0
Vcells 5452480  41.6   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums_X_S = rowCumsums(X_S), `rowCumsums(X, cols, rows)` = rowCumsums(X, 
+     rows = cols, cols = rows), `rowCumsums(X[cols, rows])` = rowCumsums(X[cols, rows]), unit = "ms")

Table: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on integer+100x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 0.008869 0.0091235 0.0092694 0.0091680 0.0092700 0.014002
2 colCumsums(X, rows, cols) 0.011110 0.0113200 0.0115046 0.0114535 0.0115590 0.014769
3 colCummins(X[rows, cols]) 0.016305 0.0167470 0.0176715 0.0168630 0.0170105 0.082477
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCumsums(X, rows, cols) 1.252678 1.240752 1.241135 1.249291 1.246926 1.054778
3 colCummins(X[rows, cols]) 1.838426 1.835589 1.906441 1.839333 1.835005 5.890373

Table: Benchmarking of rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on integer+100x100 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCumsums_X_S 0.009590 0.0097690 0.0099306 0.0098405 0.0099825 0.012150
2 rowCumsums(X, cols, rows) 0.012268 0.0125695 0.0127165 0.0126820 0.0127970 0.014458
3 rowCumsums(X[cols, rows]) 0.017095 0.0173125 0.0177939 0.0174140 0.0175460 0.041428
expr min lq mean median uq max
1 rowCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumsums(X, cols, rows) 1.279249 1.286672 1.280536 1.288756 1.281943 1.189959
3 rowCumsums(X[cols, rows]) 1.782586 1.772188 1.791829 1.769626 1.757676 3.409712

Figure: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on integer+100x100 data as well as rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

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

expr min lq mean median uq max
1 colCumsums_X_S 8.869 9.1235 9.26938 9.1680 9.2700 14.002
2 rowCumsums_X_S 9.590 9.7690 9.93058 9.8405 9.9825 12.150
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowCumsums_X_S 1.081294 1.070751 1.071332 1.073353 1.076861 0.8677332

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

1000x10 integer matrix

> X <- data[["1000x10"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3104472 165.8    5709258 305.0  5709258 305.0
Vcells 5451467  41.6   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums_X_S = colCumsums(X_S), `colCumsums(X, rows, cols)` = colCumsums(X, 
+     rows = rows, cols = cols), `colCummins(X[rows, cols])` = colCumsums(X[rows, cols]), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3104463 165.8    5709258 305.0  5709258 305.0
Vcells 5456545  41.7   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums_X_S = rowCumsums(X_S), `rowCumsums(X, cols, rows)` = rowCumsums(X, 
+     rows = cols, cols = rows), `rowCumsums(X[cols, rows])` = rowCumsums(X[cols, rows]), unit = "ms")

Table: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on integer+1000x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 0.008949 0.0090905 0.0093418 0.0091520 0.0092625 0.019732
2 colCumsums(X, rows, cols) 0.011395 0.0115845 0.0122083 0.0116745 0.0118480 0.047661
3 colCummins(X[rows, cols]) 0.016293 0.0165870 0.0168346 0.0166870 0.0168710 0.021632
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCumsums(X, rows, cols) 1.273327 1.274352 1.306837 1.275623 1.279136 2.415417
3 colCummins(X[rows, cols]) 1.820650 1.824652 1.802070 1.823317 1.821430 1.096290

Table: Benchmarking of rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on integer+1000x10 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCumsums_X_S 0.010714 0.0109080 0.0114677 0.0109875 0.011069 0.043065
2 rowCumsums(X, cols, rows) 0.014802 0.0150220 0.0154782 0.0151860 0.015338 0.031680
3 rowCumsums(X[cols, rows]) 0.019179 0.0195425 0.0198382 0.0196520 0.019839 0.023206
expr min lq mean median uq max
1 rowCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowCumsums(X, cols, rows) 1.381557 1.377154 1.349721 1.382116 1.385672 0.7356322
3 rowCumsums(X[cols, rows]) 1.790088 1.791575 1.729925 1.788578 1.792303 0.5388599

Figure: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on integer+1000x10 data as well as rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCumsums_X_S() and rowCumsums_X_S() on integer+1000x10 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 8.949 9.0905 9.34184 9.1520 9.2625 19.732
2 rowCumsums_X_S 10.714 10.9080 11.46768 10.9875 11.0690 43.065
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumsums_X_S 1.197229 1.199934 1.227561 1.200557 1.195034 2.182495

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

10x1000 integer matrix

> X <- data[["10x1000"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3104675 165.9    5709258 305.0  5709258 305.0
Vcells 5452292  41.6   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums_X_S = colCumsums(X_S), `colCumsums(X, rows, cols)` = colCumsums(X, 
+     rows = rows, cols = cols), `colCummins(X[rows, cols])` = colCumsums(X[rows, cols]), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3104669 165.9    5709258 305.0  5709258 305.0
Vcells 5457375  41.7   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums_X_S = rowCumsums(X_S), `rowCumsums(X, cols, rows)` = rowCumsums(X, 
+     rows = cols, cols = rows), `rowCumsums(X[cols, rows])` = rowCumsums(X[cols, rows]), unit = "ms")

Table: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on integer+10x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 0.009662 0.0098340 0.0101049 0.0099030 0.0100350 0.015718
2 colCumsums(X, rows, cols) 0.013462 0.0137585 0.0143464 0.0139055 0.0140770 0.040641
3 colCummins(X[rows, cols]) 0.018098 0.0183240 0.0186441 0.0184445 0.0185825 0.029034
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCumsums(X, rows, cols) 1.393293 1.399075 1.419752 1.404170 1.402790 2.585634
3 colCummins(X[rows, cols]) 1.873111 1.863331 1.845053 1.862516 1.851769 1.847182

Table: Benchmarking of rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on integer+10x1000 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCumsums_X_S 0.008849 0.0091915 0.0116850 0.0094575 0.0104240 0.052315
2 rowCumsums(X, cols, rows) 0.011865 0.0121505 0.0144906 0.0123160 0.0129315 0.025813
3 rowCumsums(X[cols, rows]) 0.016243 0.0166975 0.0205128 0.0169975 0.0214675 0.036792
expr min lq mean median uq max
1 rowCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowCumsums(X, cols, rows) 1.340829 1.321928 1.240094 1.302247 1.240551 0.4934149
3 rowCumsums(X[cols, rows]) 1.835575 1.816624 1.755473 1.797251 2.059430 0.7032782

Figure: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on integer+10x1000 data as well as rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

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

expr min lq mean median uq max
2 rowCumsums_X_S 8.849 9.1915 11.68505 9.4575 10.424 52.315
1 colCumsums_X_S 9.662 9.8340 10.10490 9.9030 10.035 15.718
expr min lq mean median uq max
2 rowCumsums_X_S 1.000000 1.000000 1.0000000 1.000000 1.0000000 1.0000000
1 colCumsums_X_S 1.091875 1.069902 0.8647717 1.047106 0.9626823 0.3004492

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

100x1000 integer matrix

> X <- data[["100x1000"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3104874 165.9    5709258 305.0  5709258 305.0
Vcells 5474952  41.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums_X_S = colCumsums(X_S), `colCumsums(X, rows, cols)` = colCumsums(X, 
+     rows = rows, cols = cols), `colCummins(X[rows, cols])` = colCumsums(X[rows, cols]), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3104868 165.9    5709258 305.0  5709258 305.0
Vcells 5525035  42.2   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums_X_S = rowCumsums(X_S), `rowCumsums(X, cols, rows)` = rowCumsums(X, 
+     rows = cols, cols = rows), `rowCumsums(X[cols, rows])` = rowCumsums(X[cols, rows]), unit = "ms")

Table: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on integer+100x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 0.078230 0.0786810 0.0814287 0.0805540 0.0827620 0.103840
2 colCumsums(X, rows, cols) 0.102959 0.1036395 0.1072950 0.1059205 0.1089395 0.203522
3 colCummins(X[rows, cols]) 0.149424 0.1508350 0.1554380 0.1542220 0.1584295 0.173873
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCumsums(X, rows, cols) 1.316106 1.317211 1.317656 1.314901 1.316299 1.959958
3 colCummins(X[rows, cols]) 1.910060 1.917045 1.908885 1.914517 1.914278 1.674432

Table: Benchmarking of rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on integer+100x1000 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCumsums_X_S 0.080971 0.0817145 0.0854440 0.0855635 0.0880130 0.113462
2 rowCumsums(X, cols, rows) 0.108171 0.1088235 0.1132731 0.1113770 0.1174945 0.142157
3 rowCumsums(X[cols, rows]) 0.144036 0.1455050 0.1515755 0.1504875 0.1561380 0.206613
expr min lq mean median uq max
1 rowCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumsums(X, cols, rows) 1.335923 1.331753 1.325699 1.301688 1.334968 1.252904
3 rowCumsums(X[cols, rows]) 1.778859 1.780651 1.773974 1.758781 1.774033 1.820988

Figure: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on integer+100x1000 data as well as rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

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

expr min lq mean median uq max
1 colCumsums_X_S 78.230 78.6810 81.42870 80.5540 82.762 103.840
2 rowCumsums_X_S 80.971 81.7145 85.44403 85.5635 88.013 113.462
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumsums_X_S 1.035038 1.038554 1.049311 1.062188 1.063447 1.092662

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

1000x100 integer matrix

> X <- data[["1000x100"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3105090 165.9    5709258 305.0  5709258 305.0
Vcells 5475735  41.8   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums_X_S = colCumsums(X_S), `colCumsums(X, rows, cols)` = colCumsums(X, 
+     rows = rows, cols = cols), `colCummins(X[rows, cols])` = colCumsums(X[rows, cols]), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3105084 165.9    5709258 305.0  5709258 305.0
Vcells 5525818  42.2   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums_X_S = rowCumsums(X_S), `rowCumsums(X, cols, rows)` = rowCumsums(X, 
+     rows = cols, cols = rows), `rowCumsums(X[cols, rows])` = rowCumsums(X[cols, rows]), unit = "ms")

Table: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on integer+1000x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 0.077934 0.0782450 0.0803459 0.078739 0.0804590 0.109437
2 colCumsums(X, rows, cols) 0.099019 0.0995635 0.1012852 0.099995 0.1021710 0.117236
3 colCummins(X[rows, cols]) 0.140786 0.1417705 0.1463169 0.143043 0.1465325 0.230693
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCumsums(X, rows, cols) 1.270549 1.272458 1.260614 1.269955 1.269852 1.071265
3 colCummins(X[rows, cols]) 1.806477 1.811879 1.821088 1.816673 1.821207 2.107998

Table: Benchmarking of rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on integer+1000x100 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCumsums_X_S 0.082305 0.0829885 0.0862274 0.0846445 0.0870410 0.158487
2 rowCumsums(X, cols, rows) 0.113623 0.1142715 0.1176942 0.1168425 0.1201635 0.138408
3 rowCumsums(X[cols, rows]) 0.153269 0.1543100 0.1599422 0.1575415 0.1617135 0.256837
expr min lq mean median uq max
1 rowCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowCumsums(X, cols, rows) 1.380511 1.376956 1.364928 1.380391 1.380539 0.8733082
3 rowCumsums(X[cols, rows]) 1.862208 1.859414 1.854888 1.861214 1.857900 1.6205556

Figure: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on integer+1000x100 data as well as rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCumsums_X_S() and rowCumsums_X_S() on integer+1000x100 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 77.934 78.2450 80.34589 78.7390 80.459 109.437
2 rowCumsums_X_S 82.305 82.9885 86.22741 84.6445 87.041 158.487
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumsums_X_S 1.056086 1.060624 1.073203 1.075001 1.081806 1.448203

Figure: Benchmarking of colCumsums_X_S() and rowCumsums_X_S() on integer+1000x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

Data type "double"

Data

> rmatrix <- function(nrow, ncol, mode = c("logical", "double", "integer", "index"), range = c(-100, 
+     +100), na_prob = 0) {
+     mode <- match.arg(mode)
+     n <- nrow * ncol
+     if (mode == "logical") {
+         x <- sample(c(FALSE, TRUE), size = n, replace = TRUE)
+     }     else if (mode == "index") {
+         x <- seq_len(n)
+         mode <- "integer"
+     }     else {
+         x <- runif(n, min = range[1], max = range[2])
+     }
+     storage.mode(x) <- mode
+     if (na_prob > 0) 
+         x[sample(n, size = na_prob * n)] <- NA
+     dim(x) <- c(nrow, ncol)
+     x
+ }
> rmatrices <- function(scale = 10, seed = 1, ...) {
+     set.seed(seed)
+     data <- list()
+     data[[1]] <- rmatrix(nrow = scale * 1, ncol = scale * 1, ...)
+     data[[2]] <- rmatrix(nrow = scale * 10, ncol = scale * 10, ...)
+     data[[3]] <- rmatrix(nrow = scale * 100, ncol = scale * 1, ...)
+     data[[4]] <- t(data[[3]])
+     data[[5]] <- rmatrix(nrow = scale * 10, ncol = scale * 100, ...)
+     data[[6]] <- t(data[[5]])
+     names(data) <- sapply(data, FUN = function(x) paste(dim(x), collapse = "x"))
+     data
+ }
> data <- rmatrices(mode = mode)

Results

10x10 double matrix

> X <- data[["10x10"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3105308 165.9    5709258 305.0  5709258 305.0
Vcells 5566835  42.5   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums_X_S = colCumsums(X_S), `colCumsums(X, rows, cols)` = colCumsums(X, 
+     rows = rows, cols = cols), `colCummins(X[rows, cols])` = colCumsums(X[rows, cols]), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3105293 165.9    5709258 305.0  5709258 305.0
Vcells 5567003  42.5   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums_X_S = rowCumsums(X_S), `rowCumsums(X, cols, rows)` = rowCumsums(X, 
+     rows = cols, cols = rows), `rowCumsums(X[cols, rows])` = rowCumsums(X[cols, rows]), unit = "ms")

Table: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on double+10x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 0.000938 0.0011375 0.0015186 0.0011875 0.0012815 0.026436
2 colCumsums(X, rows, cols) 0.001044 0.0013230 0.0014886 0.0013670 0.0014235 0.006763
3 colCummins(X[rows, cols]) 0.001757 0.0019595 0.0021692 0.0020345 0.0021905 0.009067
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
2 colCumsums(X, rows, cols) 1.113006 1.163077 0.9802775 1.151158 1.110808 0.2558254
3 colCummins(X[rows, cols]) 1.873134 1.722637 1.4284294 1.713263 1.709325 0.3429793

Table: Benchmarking of rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on double+10x10 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCumsums_X_S 0.000947 0.0011905 0.0013071 0.0012345 0.0013740 0.003033
2 rowCumsums(X, cols, rows) 0.001155 0.0013475 0.0017449 0.0014045 0.0015155 0.030485
3 rowCumsums(X[cols, rows]) 0.001381 0.0018905 0.0020243 0.0019665 0.0020785 0.005972
expr min lq mean median uq max
1 rowCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumsums(X, cols, rows) 1.219641 1.131877 1.334894 1.137708 1.102984 10.051104
3 rowCumsums(X[cols, rows]) 1.458289 1.587988 1.548691 1.592953 1.512736 1.969008

Figure: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on double+10x10 data as well as rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

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

expr min lq mean median uq max
1 colCumsums_X_S 938 1137.5 1518.57 1187.5 1281.5 26436
2 rowCumsums_X_S 947 1190.5 1307.13 1234.5 1374.0 3033
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
2 rowCumsums_X_S 1.009595 1.046593 0.8607637 1.039579 1.072181 0.1147299

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

100x100 double matrix

> X <- data[["100x100"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3105510 165.9    5709258 305.0  5709258 305.0
Vcells 5572787  42.6   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums_X_S = colCumsums(X_S), `colCumsums(X, rows, cols)` = colCumsums(X, 
+     rows = rows, cols = cols), `colCummins(X[rows, cols])` = colCumsums(X[rows, cols]), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3105504 165.9    5709258 305.0  5709258 305.0
Vcells 5582870  42.6   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums_X_S = rowCumsums(X_S), `rowCumsums(X, cols, rows)` = rowCumsums(X, 
+     rows = cols, cols = rows), `rowCumsums(X[cols, rows])` = rowCumsums(X[cols, rows]), unit = "ms")

Table: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on double+100x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 0.004876 0.0056105 0.0066016 0.0064030 0.0067430 0.037518
2 colCumsums(X, rows, cols) 0.007201 0.0075240 0.0081006 0.0078355 0.0082150 0.020917
3 colCummins(X[rows, cols]) 0.020606 0.0212055 0.0225128 0.0219750 0.0226015 0.068757
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 colCumsums(X, rows, cols) 1.476825 1.341057 1.227069 1.223723 1.218301 0.5575191
3 colCummins(X[rows, cols]) 4.226005 3.779610 3.410198 3.431985 3.351846 1.8326403

Table: Benchmarking of rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on double+100x100 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCumsums_X_S 0.004867 0.0058470 0.0064340 0.0066000 0.0069015 0.010937
2 rowCumsums(X, cols, rows) 0.006910 0.0075175 0.0078658 0.0077545 0.0080020 0.012799
3 rowCumsums(X[cols, rows]) 0.011983 0.0127130 0.0147156 0.0142500 0.0146890 0.056751
expr min lq mean median uq max
1 rowCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumsums(X, cols, rows) 1.419766 1.285702 1.222538 1.174924 1.159458 1.170248
3 rowCumsums(X[cols, rows]) 2.462092 2.174277 2.287184 2.159091 2.128378 5.188900

Figure: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on double+100x100 data as well as rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

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

expr min lq mean median uq max
1 colCumsums_X_S 4.876 5.6105 6.60160 6.403 6.7430 37.518
2 rowCumsums_X_S 4.867 5.8470 6.43396 6.600 6.9015 10.937
expr min lq mean median uq max
1 colCumsums_X_S 1.0000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
2 rowCumsums_X_S 0.9981542 1.042153 0.9746062 1.030767 1.023506 0.2915134

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

1000x10 double matrix

> X <- data[["1000x10"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3105719 165.9    5709258 305.0  5709258 305.0
Vcells 5574202  42.6   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums_X_S = colCumsums(X_S), `colCumsums(X, rows, cols)` = colCumsums(X, 
+     rows = rows, cols = cols), `colCummins(X[rows, cols])` = colCumsums(X[rows, cols]), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3105713 165.9    5709258 305.0  5709258 305.0
Vcells 5584285  42.7   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums_X_S = rowCumsums(X_S), `rowCumsums(X, cols, rows)` = rowCumsums(X, 
+     rows = cols, cols = rows), `rowCumsums(X[cols, rows])` = rowCumsums(X[cols, rows]), unit = "ms")

Table: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on double+1000x10 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 0.006142 0.0065105 0.0070593 0.0067060 0.0069005 0.037865
2 colCumsums(X, rows, cols) 0.007279 0.0077485 0.0083504 0.0079780 0.0082525 0.033318
3 colCummins(X[rows, cols]) 0.021825 0.0221825 0.0226832 0.0224665 0.0227530 0.032226
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 colCumsums(X, rows, cols) 1.185119 1.190154 1.182901 1.189681 1.195928 0.8799155
3 colCummins(X[rows, cols]) 3.553403 3.407188 3.213236 3.350209 3.297297 0.8510762

Table: Benchmarking of rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on double+1000x10 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCumsums_X_S 0.005536 0.0063860 0.0079109 0.0070035 0.0075925 0.066193
2 rowCumsums(X, cols, rows) 0.008967 0.0096615 0.0112197 0.0100155 0.0103615 0.050766
3 rowCumsums(X[cols, rows]) 0.014483 0.0153645 0.0165678 0.0160385 0.0167525 0.057295
expr min lq mean median uq max
1 rowCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowCumsums(X, cols, rows) 1.619762 1.512919 1.418253 1.430071 1.364702 0.7669391
3 rowCumsums(X[cols, rows]) 2.616149 2.405966 2.094297 2.290069 2.206454 0.8655749

Figure: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on double+1000x10 data as well as rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

Table: Benchmarking of colCumsums_X_S() and rowCumsums_X_S() on double+1000x10 data (original and transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 6.142 6.5105 7.0593 6.7060 6.9005 37.865
2 rowCumsums_X_S 5.536 6.3860 7.9109 7.0035 7.5925 66.193
expr min lq mean median uq max
1 colCumsums_X_S 1.0000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumsums_X_S 0.9013351 0.980877 1.120635 1.044363 1.100283 1.748131

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

10x1000 double matrix

> X <- data[["10x1000"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3105925 165.9    5709258 305.0  5709258 305.0
Vcells 5574339  42.6   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums_X_S = colCumsums(X_S), `colCumsums(X, rows, cols)` = colCumsums(X, 
+     rows = rows, cols = cols), `colCummins(X[rows, cols])` = colCumsums(X[rows, cols]), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3105919 165.9    5709258 305.0  5709258 305.0
Vcells 5584422  42.7   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums_X_S = rowCumsums(X_S), `rowCumsums(X, cols, rows)` = rowCumsums(X, 
+     rows = cols, cols = rows), `rowCumsums(X[cols, rows])` = rowCumsums(X[cols, rows]), unit = "ms")

Table: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on double+10x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 0.005284 0.0059175 0.0064668 0.006455 0.0069105 0.010176
2 colCumsums(X, rows, cols) 0.008730 0.0093220 0.0099642 0.009489 0.0096980 0.053247
3 colCummins(X[rows, cols]) 0.014206 0.0152290 0.0163452 0.016003 0.0164475 0.045689
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 colCumsums(X, rows, cols) 1.652157 1.575327 1.540837 1.470023 1.403372 5.232606
3 colCummins(X[rows, cols]) 2.688494 2.573553 2.527574 2.479163 2.380074 4.489878

Table: Benchmarking of rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on double+10x1000 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCumsums_X_S 0.004262 0.0048790 0.0059595 0.0059720 0.0064010 0.023056
2 rowCumsums(X, cols, rows) 0.006723 0.0071615 0.0075589 0.0074525 0.0078235 0.012179
3 rowCumsums(X[cols, rows]) 0.011846 0.0124505 0.0140730 0.0138305 0.0143600 0.048729
expr min lq mean median uq max
1 rowCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 rowCumsums(X, cols, rows) 1.577428 1.467821 1.268388 1.247907 1.222231 0.5282356
3 rowCumsums(X[cols, rows]) 2.779446 2.551855 2.361452 2.315891 2.243400 2.1135062

Figure: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on double+10x1000 data as well as rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

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

expr min lq mean median uq max
2 rowCumsums_X_S 4.262 4.8790 5.95946 5.972 6.4010 23.056
1 colCumsums_X_S 5.284 5.9175 6.46677 6.455 6.9105 10.176
expr min lq mean median uq max
2 rowCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
1 colCumsums_X_S 1.239793 1.212851 1.085127 1.080877 1.079597 0.4413602

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

100x1000 double matrix

> X <- data[["100x1000"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3106124 165.9    5709258 305.0  5709258 305.0
Vcells 5619780  42.9   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums_X_S = colCumsums(X_S), `colCumsums(X, rows, cols)` = colCumsums(X, 
+     rows = rows, cols = cols), `colCummins(X[rows, cols])` = colCumsums(X[rows, cols]), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3106118 165.9    5709258 305.0  5709258 305.0
Vcells 5719863  43.7   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums_X_S = rowCumsums(X_S), `rowCumsums(X, cols, rows)` = rowCumsums(X, 
+     rows = cols, cols = rows), `rowCumsums(X[cols, rows])` = rowCumsums(X[cols, rows]), unit = "ms")

Table: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on double+100x1000 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 0.040634 0.0427765 0.0919119 0.0517375 0.145239 0.184779
2 colCumsums(X, rows, cols) 0.065526 0.0666270 0.1077700 0.0780885 0.170729 0.177745
3 colCummins(X[rows, cols]) 0.192238 0.1949405 0.3477559 0.2299750 0.398020 7.181248
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.0000000
2 colCumsums(X, rows, cols) 1.612590 1.557561 1.172537 1.509321 1.175504 0.9619329
3 colCummins(X[rows, cols]) 4.730964 4.557187 3.783581 4.445035 2.740448 38.8639835

Table: Benchmarking of rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on double+100x1000 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCumsums_X_S 0.033994 0.0367225 0.0760651 0.0410395 0.1332505 0.160762
2 rowCumsums(X, cols, rows) 0.057126 0.0582200 0.1013315 0.0705625 0.1619285 0.176954
3 rowCumsums(X[cols, rows]) 0.107283 0.1113780 0.2644410 0.1324595 0.3065900 7.016414
expr min lq mean median uq max
1 rowCumsums_X_S 1.000000 1.000000 1.000000 1.00000 1.000000 1.00000
2 rowCumsums(X, cols, rows) 1.680473 1.585404 1.332168 1.71938 1.215219 1.10072
3 rowCumsums(X[cols, rows]) 3.155939 3.032963 3.476510 3.22761 2.300854 43.64473

Figure: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on double+100x1000 data as well as rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

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

expr min lq mean median uq max
2 rowCumsums_X_S 33.994 36.7225 76.06506 41.0395 133.2505 160.762
1 colCumsums_X_S 40.634 42.7765 91.91186 51.7375 145.2390 184.779
expr min lq mean median uq max
2 rowCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.00000 1.000000
1 colCumsums_X_S 1.195329 1.164858 1.208332 1.260676 1.08997 1.149395

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

1000x100 double matrix

> X <- data[["1000x100"]]
> rows <- sample.int(nrow(X), size = nrow(X) * 0.7)
> cols <- sample.int(ncol(X), size = ncol(X) * 0.7)
> X_S <- X[rows, cols]
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3106340 165.9    5709258 305.0  5709258 305.0
Vcells 5619927  42.9   22267496 169.9 56666022 432.4
> colStats <- microbenchmark(colCumsums_X_S = colCumsums(X_S), `colCumsums(X, rows, cols)` = colCumsums(X, 
+     rows = rows, cols = cols), `colCummins(X[rows, cols])` = colCumsums(X[rows, cols]), unit = "ms")
> X <- t(X)
> X_S <- t(X_S)
> gc()
          used  (Mb) gc trigger  (Mb) max used  (Mb)
Ncells 3106334 165.9    5709258 305.0  5709258 305.0
Vcells 5720010  43.7   22267496 169.9 56666022 432.4
> rowStats <- microbenchmark(rowCumsums_X_S = rowCumsums(X_S), `rowCumsums(X, cols, rows)` = rowCumsums(X, 
+     rows = cols, cols = rows), `rowCumsums(X[cols, rows])` = rowCumsums(X[cols, rows]), unit = "ms")

Table: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on double+1000x100 data. The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 colCumsums_X_S 0.052020 0.053259 0.1602918 0.0632195 0.1511970 6.956892
2 colCumsums(X, rows, cols) 0.060491 0.061178 0.1039356 0.0709300 0.1602520 0.193273
3 colCummins(X[rows, cols]) 0.120244 0.123329 0.2090293 0.1475340 0.3202545 0.336265
expr min lq mean median uq max
1 colCumsums_X_S 1.000000 1.000000 1.0000000 1.000000 1.000000 1.0000000
2 colCumsums(X, rows, cols) 1.162841 1.148689 0.6484149 1.121964 1.059889 0.0277815
3 colCummins(X[rows, cols]) 2.311496 2.315646 1.3040547 2.333679 2.118127 0.0483355

Table: Benchmarking of rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on double+1000x100 data (transposed). The top panel shows times in milliseconds and the bottom panel shows relative times.

expr min lq mean median uq max
1 rowCumsums_X_S 0.039218 0.0415890 0.0815020 0.0467490 0.1326775 0.140161
2 rowCumsums(X, cols, rows) 0.065406 0.0670280 0.1750258 0.0777910 0.1651680 6.323510
3 rowCumsums(X[cols, rows]) 0.117334 0.1217225 0.1912891 0.1341145 0.3057490 0.319153
expr min lq mean median uq max
1 rowCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
2 rowCumsums(X, cols, rows) 1.667755 1.611676 2.147504 1.664014 1.244883 45.116045
3 rowCumsums(X[cols, rows]) 2.991840 2.926795 2.347049 2.868821 2.304453 2.277046

Figure: Benchmarking of colCumsums_X_S(), colCumsums(X, rows, cols)() and colCummins(X[rows, cols])() on double+1000x100 data as well as rowCumsums_X_S(), rowCumsums(X, cols, rows)() and rowCumsums(X[cols, rows])() on the same data transposed. Outliers are displayed as crosses. Times are in milliseconds.

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

expr min lq mean median uq max
2 rowCumsums_X_S 39.218 41.589 81.50198 46.7490 132.6775 140.161
1 colCumsums_X_S 52.020 53.259 160.29184 63.2195 151.1970 6956.892
expr min lq mean median uq max
2 rowCumsums_X_S 1.000000 1.000000 1.000000 1.000000 1.000000 1.00000
1 colCumsums_X_S 1.326432 1.280603 1.966723 1.352318 1.139583 49.63501

Figure: Benchmarking of colCumsums_X_S() and rowCumsums_X_S() on double+1000x100 data (original and transposed). Outliers are displayed as crosses. Times are in milliseconds.

Appendix

Session information

R version 3.6.1 Patched (2019-08-27 r77078)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.3 LTS

Matrix products: default
BLAS:   /home/hb/software/R-devel/R-3-6-branch/lib/R/lib/libRblas.so
LAPACK: /home/hb/software/R-devel/R-3-6-branch/lib/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] microbenchmark_1.4-6    matrixStats_0.55.0-9000 ggplot2_3.2.1          
[4] knitr_1.24              R.devices_2.16.0        R.utils_2.9.0          
[7] R.oo_1.22.0             R.methodsS3_1.7.1       history_0.0.0-9002     

loaded via a namespace (and not attached):
 [1] Biobase_2.45.0       bit64_0.9-7          splines_3.6.1       
 [4] network_1.15         assertthat_0.2.1     highr_0.8           
 [7] stats4_3.6.1         blob_1.2.0           robustbase_0.93-5   
[10] pillar_1.4.2         RSQLite_2.1.2        backports_1.1.4     
[13] lattice_0.20-38      glue_1.3.1           digest_0.6.20       
[16] colorspace_1.4-1     sandwich_2.5-1       Matrix_1.2-17       
[19] XML_3.98-1.20        lpSolve_5.6.13.3     pkgconfig_2.0.2     
[22] genefilter_1.66.0    purrr_0.3.2          ergm_3.10.4         
[25] xtable_1.8-4         mvtnorm_1.0-11       scales_1.0.0        
[28] tibble_2.1.3         annotate_1.62.0      IRanges_2.18.2      
[31] TH.data_1.0-10       withr_2.1.2          BiocGenerics_0.30.0 
[34] lazyeval_0.2.2       mime_0.7             survival_2.44-1.1   
[37] magrittr_1.5         crayon_1.3.4         statnet.common_4.3.0
[40] memoise_1.1.0        laeken_0.5.0         R.cache_0.13.0      
[43] MASS_7.3-51.4        R.rsp_0.43.1         tools_3.6.1         
[46] multcomp_1.4-10      S4Vectors_0.22.1     trust_0.1-7         
[49] munsell_0.5.0        AnnotationDbi_1.46.1 compiler_3.6.1      
[52] rlang_0.4.0          grid_3.6.1           RCurl_1.95-4.12     
[55] cwhmisc_6.6          rappdirs_0.3.1       labeling_0.3        
[58] bitops_1.0-6         base64enc_0.1-3      boot_1.3-23         
[61] gtable_0.3.0         codetools_0.2-16     DBI_1.0.0           
[64] markdown_1.1         R6_2.4.0             zoo_1.8-6           
[67] dplyr_0.8.3          bit_1.1-14           zeallot_0.1.0       
[70] parallel_3.6.1       Rcpp_1.0.2           vctrs_0.2.0         
[73] DEoptimR_1.0-8       tidyselect_0.2.5     xfun_0.9            
[76] coda_0.19-3         

Total processing time was 22.49 secs.

Reproducibility

To reproduce this report, do:

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

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